opkg

statically linked package installer
git clone anongit@rnpnr.xyz:opkg.git
Log | Files | Refs | Feed | Submodules | README | LICENSE

0003-Avoid-pointer-arithmetic-on-void.patch (4863B)


      1 From c154f9dfaaccabc52af12ccabc86e9d0c6c18ada Mon Sep 17 00:00:00 2001
      2 From: Michael Forney <mforney@mforney.org>
      3 Date: Sun, 7 Jul 2019 21:25:13 -0700
      4 Subject: [PATCH] Avoid pointer arithmetic on `void *`
      5 
      6 ---
      7  src/netlink_smc_diag.c |  4 ++--
      8  src/print_timespec.h   |  6 ++++--
      9  src/sockaddr.c         |  4 ++--
     10  src/tee.c              |  2 +-
     11  src/ucopy.c            | 12 ++++++------
     12  5 files changed, 15 insertions(+), 13 deletions(-)
     13 
     14 diff --git a/src/netlink_smc_diag.c b/src/netlink_smc_diag.c
     15 index 74e78b966..c3a28a839 100644
     16 --- a/src/netlink_smc_diag.c
     17 +++ b/src/netlink_smc_diag.c
     18 @@ -42,7 +42,7 @@ DECL_NETLINK_DIAG_DECODER(decode_smc_diag_req)
     19  	if (len >= sizeof(req)) {
     20  		if (!umoven_or_printaddr(tcp, addr + offset,
     21  					 sizeof(req) - offset,
     22 -					 (void *) &req + offset)) {
     23 +					 (char *) &req + offset)) {
     24  			PRINT_FIELD_FLAGS(req, diag_ext,
     25  					  smc_diag_extended_flags,
     26  					  "1<<SMC_DIAG_\?\?\?-1");
     27 @@ -261,7 +261,7 @@ DECL_NETLINK_DIAG_DECODER(decode_smc_diag_msg)
     28  	if (len >= sizeof(msg)) {
     29  		if (!umoven_or_printaddr(tcp, addr + offset,
     30  					 sizeof(msg) - offset,
     31 -					 (void *) &msg + offset)) {
     32 +					 (char *) &msg + offset)) {
     33  			PRINT_FIELD_XVAL(msg, diag_state,
     34  					 smc_states, "SMC_???");
     35  			tprint_struct_next();
     36 diff --git a/src/print_timespec.h b/src/print_timespec.h
     37 index dc5f9d10c..87f7ff973 100644
     38 --- a/src/print_timespec.h
     39 +++ b/src/print_timespec.h
     40 @@ -66,6 +66,8 @@ bool
     41  PRINT_TIMESPEC_ARRAY_DATA_SIZE(const void *arg, const unsigned int nmemb,
     42  			       const size_t size)
     43  {
     44 +	const char *ts = arg;
     45 +
     46  	if (nmemb > size / sizeof(TIMESPEC_T)) {
     47  		tprint_unavailable();
     48  		return false;
     49 @@ -73,10 +75,10 @@ PRINT_TIMESPEC_ARRAY_DATA_SIZE(const void *arg, const unsigned int nmemb,
     50  
     51  	tprint_array_begin();
     52  
     53 -	for (unsigned int i = 0; i < nmemb; i++, arg += sizeof(TIMESPEC_T)) {
     54 +	for (unsigned int i = 0; i < nmemb; i++, ts += sizeof(TIMESPEC_T)) {
     55  		if (i)
     56  			tprint_array_next();
     57 -		print_unaligned_timespec_t(arg);
     58 +		print_unaligned_timespec_t(ts);
     59  	}
     60  
     61  	tprint_array_end();
     62 diff --git a/src/sockaddr.c b/src/sockaddr.c
     63 index ee1ce8828..c1f9b1740 100644
     64 --- a/src/sockaddr.c
     65 +++ b/src/sockaddr.c
     66 @@ -583,7 +583,7 @@ print_sockaddr_data_ll(struct tcb *tcp, const void *const buf,
     67  static void
     68  print_sockaddr_data_raw(const void *const buf, const int addrlen)
     69  {
     70 -	const char *const data = buf + SIZEOF_SA_FAMILY;
     71 +	const char *const data = (const char *)buf + SIZEOF_SA_FAMILY;
     72  	const int datalen = addrlen - SIZEOF_SA_FAMILY;
     73  
     74  	tprints_field_name("sa_data");
     75 @@ -780,7 +780,7 @@ print_sockaddr_data_rxrpc(struct tcb *tcp, const void *const buf,
     76  	tprints_field_name("transport");
     77  	tprint_struct_begin();
     78  
     79 -	const void *const transport_buf = (void *) &sa->transport
     80 +	const void *const transport_buf = (char *) &sa->transport
     81  					  + sizeof(sa->transport.family);
     82  	const int transport_len = MIN(sa->transport_len,
     83  				      len - offsetof(struct sockaddr_rxrpc,
     84 diff --git a/src/tee.c b/src/tee.c
     85 index c62566800..1596a5095 100644
     86 --- a/src/tee.c
     87 +++ b/src/tee.c
     88 @@ -69,7 +69,7 @@ tee_fetch_buf_data(struct tcb *const tcp,
     89  		tee_print_buf(buf);
     90  		return RVAL_IOCTL_DECODED;
     91  	}
     92 -	uint32_t *num_params = (uint32_t *) (arg_struct + num_params_offs);
     93 +	uint32_t *num_params = (uint32_t *) ((char *)arg_struct + num_params_offs);
     94  	if (entering(tcp) &&
     95  	    (arg_size + TEE_IOCTL_PARAM_SIZE(*num_params) != buf->buf_len)) {
     96  		/*
     97 diff --git a/src/ucopy.c b/src/ucopy.c
     98 index b4e746b0b..007b5373e 100644
     99 --- a/src/ucopy.c
    100 +++ b/src/ucopy.c
    101 @@ -186,7 +186,7 @@ vm_read_mem(const pid_t pid, void *laddr,
    102  			break;
    103  
    104  		len = next_len;
    105 -		laddr += copy_len;
    106 +		laddr = (char *)laddr + copy_len;
    107  		page_start += page_size;
    108  		taddr = page_start;
    109  	}
    110 @@ -282,7 +282,7 @@ umoven_peekdata(const int pid, kernel_ulong_t addr, unsigned int len,
    111  		memcpy(laddr, &u.data[residue], m);
    112  		residue = 0;
    113  		addr += sizeof(long);
    114 -		laddr += m;
    115 +		laddr = (char *)laddr + m;
    116  		nread += m;
    117  		len -= m;
    118  	}
    119 @@ -378,10 +378,10 @@ umovestr_peekdata(const int pid, kernel_ulong_t addr, unsigned int len,
    120  		memcpy(laddr, &u.data[residue], m);
    121  		while (residue < sizeof(long))
    122  			if (u.data[residue++] == '\0')
    123 -				return (laddr - orig_addr) + residue;
    124 +				return nread + residue;
    125  		residue = 0;
    126  		addr += sizeof(long);
    127 -		laddr += m;
    128 +		laddr = (char *)laddr + m;
    129  		nread += m;
    130  		len -= m;
    131  	}
    132 @@ -502,7 +502,7 @@ upoken_pokedata(const int pid, kernel_ulong_t addr, unsigned int len,
    133  
    134  		addr += sizeof(long);
    135  		nwritten += npoke;
    136 -		our_addr += npoke;
    137 +		our_addr = (char *)our_addr + npoke;
    138  		len -= npoke;
    139  	}
    140  
    141 @@ -515,7 +515,7 @@ upoken_pokedata(const int pid, kernel_ulong_t addr, unsigned int len,
    142  
    143  		addr += sizeof(long);
    144  		nwritten += sizeof(long);
    145 -		our_addr += sizeof(long);
    146 +		our_addr = (char *)our_addr + sizeof(long);
    147  		len -= sizeof(long);
    148  	}
    149  
    150 -- 
    151 2.44.0
    152