opkg

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

0025-rsync-Avoid-pointer-arithmetic-on-void.patch (4569B)


      1 From b93dee95670eccc6a5c34f1f8a3b828998d0da7b Mon Sep 17 00:00:00 2001
      2 From: Michael Forney <mforney@mforney.org>
      3 Date: Sat, 15 Jun 2019 20:06:13 -0700
      4 Subject: [PATCH] rsync: Avoid pointer arithmetic on `void *`
      5 
      6 ---
      7  usr.bin/rsync/blocks.c     |  8 ++++----
      8  usr.bin/rsync/downloader.c |  2 +-
      9  usr.bin/rsync/io.c         | 12 ++++++------
     10  usr.bin/rsync/sender.c     |  5 +++--
     11  4 files changed, 14 insertions(+), 13 deletions(-)
     12 
     13 diff --git a/usr.bin/rsync/blocks.c b/usr.bin/rsync/blocks.c
     14 index 56790729f27..906733c968e 100644
     15 --- a/usr.bin/rsync/blocks.c
     16 +++ b/usr.bin/rsync/blocks.c
     17 @@ -157,7 +157,7 @@ blk_find(struct sess *sess, struct blkstat *st,
     18  	if (!recomp) {
     19  		fhash = (st->s1 & 0xFFFF) | (st->s2 << 16);
     20  	} else {
     21 -		fhash = hash_fast(st->map + st->offs, (size_t)osz);
     22 +		fhash = hash_fast((char *)st->map + st->offs, (size_t)osz);
     23  		st->s1 = fhash & 0xFFFF;
     24  		st->s2 = fhash >> 16;
     25  	}
     26 @@ -170,7 +170,7 @@ blk_find(struct sess *sess, struct blkstat *st,
     27  	if (st->hint < blks->blksz &&
     28  	    fhash == blks->blks[st->hint].chksum_short &&
     29  	    (size_t)osz == blks->blks[st->hint].len) {
     30 -		hash_slow(st->map + st->offs, (size_t)osz, md, sess);
     31 +		hash_slow((char *)st->map + st->offs, (size_t)osz, md, sess);
     32  		have_md = 1;
     33  		if (memcmp(md, blks->blks[st->hint].chksum_long, blks->csum) == 0) {
     34  			LOG4("%s: found matching hinted match: "
     35 @@ -203,7 +203,7 @@ blk_find(struct sess *sess, struct blkstat *st,
     36  		    (intmax_t)ent->blk->offs, ent->blk->len);
     37  
     38  		if (have_md == 0) {
     39 -			hash_slow(st->map + st->offs, (size_t)osz, md, sess);
     40 +			hash_slow((char *)st->map + st->offs, (size_t)osz, md, sess);
     41  			have_md = 1;
     42  		}
     43  
     44 @@ -221,7 +221,7 @@ blk_find(struct sess *sess, struct blkstat *st,
     45  	 * block in the sequence.
     46  	 */
     47  
     48 -	map = st->map + st->offs;
     49 +	map = (char *)st->map + st->offs;
     50  	st->s1 -= map[0];
     51  	st->s2 -= osz * map[0];
     52  
     53 diff --git a/usr.bin/rsync/downloader.c b/usr.bin/rsync/downloader.c
     54 index cab6eb23f9f..07ec334f6b4 100644
     55 --- a/usr.bin/rsync/downloader.c
     56 +++ b/usr.bin/rsync/downloader.c
     57 @@ -495,7 +495,7 @@ again:
     58  		sz = tok == p->blk.blksz - 1 ? p->blk.rem : p->blk.len;
     59  		assert(sz);
     60  		assert(p->map != MAP_FAILED);
     61 -		buf = p->map + (tok * p->blk.len);
     62 +		buf = (char *)p->map + (tok * p->blk.len);
     63  
     64  		/*
     65  		 * Now we read from our block.
     66 diff --git a/usr.bin/rsync/io.c b/usr.bin/rsync/io.c
     67 index dc224ae8aed..fcf9e92dbaa 100644
     68 --- a/usr.bin/rsync/io.c
     69 +++ b/usr.bin/rsync/io.c
     70 @@ -117,7 +117,7 @@ io_write_blocking(int fd, const void *buf, size_t sz)
     71  			ERRX("io_write_nonblocking: short write");
     72  			return 0;
     73  		}
     74 -		buf += wsz;
     75 +		buf = (char *)buf + wsz;
     76  		sz -= wsz;
     77  	}
     78  
     79 @@ -156,7 +156,7 @@ io_write_buf(struct sess *sess, int fd, const void *buf, size_t sz)
     80  		}
     81  		sess->total_write += wsz;
     82  		sz -= wsz;
     83 -		buf += wsz;
     84 +		buf = (char *)buf + wsz;
     85  	}
     86  
     87  	return 1;
     88 @@ -250,7 +250,7 @@ io_read_blocking(int fd, void *buf, size_t sz)
     89  			ERRX("io_read_nonblocking: short read");
     90  			return 0;
     91  		}
     92 -		buf += rsz;
     93 +		buf = (char *)buf + rsz;
     94  		sz -= rsz;
     95  	}
     96  
     97 @@ -367,7 +367,7 @@ io_read_buf(struct sess *sess, int fd, void *buf, size_t sz)
     98  			}
     99  			sz -= rsz;
    100  			sess->mplex_read_remain -= rsz;
    101 -			buf += rsz;
    102 +			buf = (char *)buf + rsz;
    103  			sess->total_read += rsz;
    104  			continue;
    105  		}
    106 @@ -463,7 +463,7 @@ io_buffer_buf(void *buf, size_t *bufpos, size_t buflen, const void *val,
    107  {
    108  
    109  	assert(*bufpos + valsz <= buflen);
    110 -	memcpy(buf + *bufpos, val, valsz);
    111 +	memcpy((char *)buf + *bufpos, val, valsz);
    112  	*bufpos += valsz;
    113  }
    114  
    115 @@ -662,7 +662,7 @@ io_unbuffer_buf(const void *buf, size_t *bufpos, size_t bufsz, void *val,
    116  {
    117  
    118  	assert(*bufpos + valsz <= bufsz);
    119 -	memcpy(val, buf + *bufpos, valsz);
    120 +	memcpy(val, (char *)buf + *bufpos, valsz);
    121  	*bufpos += valsz;
    122  }
    123  
    124 diff --git a/usr.bin/rsync/sender.c b/usr.bin/rsync/sender.c
    125 index e2999aa2589..9dd008def01 100644
    126 --- a/usr.bin/rsync/sender.c
    127 +++ b/usr.bin/rsync/sender.c
    128 @@ -128,7 +128,7 @@ send_up_fsm(struct sess *sess, size_t *phase,
    129  			return 0;
    130  		}
    131  		io_lowbuffer_buf(sess, *wb, &pos, *wbsz,
    132 -			up->stat.map + up->stat.curpos, sz);
    133 +			(char *)up->stat.map + up->stat.curpos, sz);
    134  
    135  		up->stat.curpos += sz;
    136  		if (up->stat.curpos == up->stat.curlen)
    137 @@ -557,7 +557,8 @@ rsync_sender(struct sess *sess, int fdin,
    138  		if ((pfd[1].revents & POLLOUT) && wbufsz > 0) {
    139  			assert(pfd[2].fd == -1);
    140  			assert(wbufsz - wbufpos);
    141 -			ssz = write(fdout, wbuf + wbufpos, wbufsz - wbufpos);
    142 +			ssz = write(fdout,
    143 +				(char *)wbuf + wbufpos, wbufsz - wbufpos);
    144  			if (ssz == -1) {
    145  				ERR("write");
    146  				goto out;
    147 -- 
    148 2.37.3
    149