Date: Mon, 28 Oct 2013 11:16:58 GMT From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r259106 - soc2013/dpl/head/usr.bin/bsdiff/bsdiff Message-ID: <201310281116.r9SBGw2w039707@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dpl Date: Mon Oct 28 11:16:58 2013 New Revision: 259106 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=259106 Log: Use only one right and make the fd have coherent names. Modified: soc2013/dpl/head/usr.bin/bsdiff/bsdiff/bsdiff.c Modified: soc2013/dpl/head/usr.bin/bsdiff/bsdiff/bsdiff.c ============================================================================== --- soc2013/dpl/head/usr.bin/bsdiff/bsdiff/bsdiff.c Mon Oct 28 10:32:14 2013 (r259105) +++ soc2013/dpl/head/usr.bin/bsdiff/bsdiff/bsdiff.c Mon Oct 28 11:16:58 2013 (r259106) @@ -197,7 +197,7 @@ int main(int argc,char *argv[]) { - int first, second; + int oldfd,newfd; u_char *old,*new; off_t oldsize,newsize; off_t *I,*V; @@ -218,35 +218,40 @@ if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]); - if ((first = open(argv[1],O_RDONLY|O_BINARY,0)) < 0) + /* Capsicum */ + if ((oldfd = open(argv[1],O_RDONLY|O_BINARY,0)) < 0) err(1,"%s",argv[1]); - if ((second = open(argv[2], O_RDONLY|O_BINARY, 0)) < 0) + if ((newfd = open(argv[2],O_RDONLY|O_BINARY,0)) < 0) err(1,"%s",argv[1]); /* Create the patch file */ - if ((pf = fopen(argv[3], "wb")) == NULL) - err(1, "%s", argv[3]); + if ((pf = fopen(argv[3],"wb")) == NULL) + err(1,"%s",argv[3]); - cap_rights_init(&rights, CAP_READ, CAP_SEEK); - - if (cap_rights_limit(first, &filerights) < 0 && errno != ENOSYS) - err(1, "Couldn't limit fd"); - if (cap_rights_limit(second, &filerights) < 0 && errno != ENOSYS) - err(1, "Couldn't limit fd"); - - cap_rights_set(&rights, CAP_WRITE, CAP_SEEK); - if (cap_rights_limit(fileno(pf), &pathrights) < 0 && errno != ENOSYS) - err(1, "Couldn't limit fd"); + cap_rights_init(&rights,CAP_READ,CAP_SEEK); + if (cap_rights_limit(oldfd,&filerights) < 0 && errno != ENOSYS) + err(1,"Couldn't limit fd"); + if (cap_rights_limit(newfd,&filerights) < 0 && errno != ENOSYS) + err(1,"Couldn't limit fd"); + + cap_rights_init(&rights,CAP_WRITE,CAP_SEEK); + if (cap_rights_limit(fileno(pf),&pathrights) < 0 && errno != ENOSYS) + err(1,"Couldn't limit fd"); if (cap_enter() < 0 && errno != ENOSYS) - err(1, "Couldn't enter capability mode"); + err(1,"Couldn't enter capability mode"); /* Allocate oldsize+1 bytes instead of oldsize bytes to ensure that we never try to malloc(0) and get a NULL pointer */ - if(((oldsize=lseek(first,0,SEEK_END))==-1) || - ((old=malloc(oldsize+1))==NULL) || - (lseek(first,0,SEEK_SET)!=0) || - (read(first,old,oldsize)!=oldsize) || - (close(first)==-1)) err(1,"%s",argv[1]); + if ((oldsize = lseek(oldfd,0,SEEK_END)) == -1) + err(1,"%s",argv[1]); + if ((old = malloc(oldsize + 1)) == NULL) + err(1,"%s",argv[1]); + if ((lseek(oldfd,0,SEEK_SET) != 0) + err(1,"%s",argv[1]); + if (read(oldfd,old,oldsize) != oldsize) + err(1,"%s",argv[1]); + if (close(oldfd) == -1) + err(1,"%s",argv[1]); if(((I=malloc((oldsize+1)*sizeof(off_t)))==NULL) || ((V=malloc((oldsize+1)*sizeof(off_t)))==NULL)) err(1,NULL); @@ -257,11 +262,16 @@ /* Allocate newsize+1 bytes instead of newsize bytes to ensure that we never try to malloc(0) and get a NULL pointer */ - if(((newsize=lseek(second,0,SEEK_END))==-1) || - ((new=malloc(newsize+1))==NULL) || - (lseek(second,0,SEEK_SET)!=0) || - (read(second,new,newsize)!=newsize) || - (close(second)==-1)) err(1,"%s",argv[2]); + if ((newsize = lseek(newfd,0,SEEK_END)) == -1) + err(1,"%s",argv[1]); + if ((old = malloc(newsize + 1)) == NULL) + err(1,"%s",argv[1]); + if ((lseek(newfd,0,SEEK_SET) != 0) + err(1,"%s",argv[1]); + if (read(newfd,old,newsize) != newsize) + err(1,"%s",argv[1]); + if (close(newfd) == -1) + err(1,"%s",argv[1]); if(((db=malloc(newsize+1))==NULL) || ((eb=malloc(newsize+1))==NULL)) err(1,NULL); @@ -288,8 +298,15 @@ /* Compute the differences, writing ctrl as we go */ if ((pfbz2 = BZ2_bzWriteOpen(&bz2err, pf, 9, 0, 0)) == NULL) errx(1, "BZ2_bzWriteOpen, bz2err = %d", bz2err); - scan=0;len=0;pos=0; - lastscan=0;lastpos=0;lastoffset=0; + + scan=0; + len=0; + pos=0; + + lastscan=0; + lastpos=0; + lastoffset=0; + while(scan<newsize) { oldscore=0;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201310281116.r9SBGw2w039707>