Date: Tue, 5 Dec 2006 05:28:26 GMT From: anatoly<techtonik@php.net> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/106358: [patch] bsdiff - explicitly open files in binary mode Message-ID: <200612050528.kB55SQt7020756@www.freebsd.org> Resent-Message-ID: <200612050530.kB55UBvj094826@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 106358 >Category: misc >Synopsis: [patch] bsdiff - explicitly open files in binary mode >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Dec 05 05:30:07 GMT 2006 >Closed-Date: >Last-Modified: >Originator: anatoly >Release: 6.2-RC1 >Organization: BSUIR >Environment: >Description: bsdiff relies on default behavior of underlying operating system to work with files. It assumes that files are opened in binary mode by default. This might not be true for some platforms. For example, the problem exists on windows platform. This patch explicitly opens files in binary mode. >How-To-Repeat: >Fix: Patch attached with submission follows: diff -u3 -r src_old\usr.bin\bsdiff\bsdiff\bsdiff.c src\usr.bin\bsdiff\bsdiff\bsdiff.c --- src_old\usr.bin\bsdiff\bsdiff\bsdiff.c Fri Dec 01 07:45:24 2006 +++ src\usr.bin\bsdiff\bsdiff\bsdiff.c Tue Dec 05 07:16:48 2006 @@ -216,7 +216,7 @@ /* Allocate oldsize+1 bytes instead of oldsize bytes to ensure that we never try to malloc(0) and get a NULL pointer */ - if(((fd=open(argv[1],O_RDONLY,0))<0) || + if(((fd=open(argv[1],O_RDONLY|O_BINARY,0))<0) || ((oldsize=lseek(fd,0,SEEK_END))==-1) || ((old=malloc(oldsize+1))==NULL) || (lseek(fd,0,SEEK_SET)!=0) || @@ -232,7 +232,7 @@ /* Allocate newsize+1 bytes instead of newsize bytes to ensure that we never try to malloc(0) and get a NULL pointer */ - if(((fd=open(argv[2],O_RDONLY,0))<0) || + if(((fd=open(argv[2],O_RDONLY|O_BINARY,0))<0) || ((newsize=lseek(fd,0,SEEK_END))==-1) || ((new=malloc(newsize+1))==NULL) || (lseek(fd,0,SEEK_SET)!=0) || @@ -245,7 +245,7 @@ eblen=0; /* Create the patch file */ - if ((pf = fopen(argv[3], "w")) == NULL) + if ((pf = fopen(argv[3], "wb")) == NULL) err(1, "%s", argv[3]); /* Header is diff -u3 -r src_old\usr.bin\bsdiff\bspatch\bspatch.c src\usr.bin\bsdiff\bspatch\bspatch.c --- src_old\usr.bin\bsdiff\bspatch\bspatch.c Tue Dec 05 07:21:14 2006 +++ src\usr.bin\bsdiff\bspatch\bspatch.c Tue Dec 05 07:24:12 2006 @@ -71,7 +71,7 @@ if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]); /* Open patch file */ - if ((f = fopen(argv[3], "r")) == NULL) + if ((f = fopen(argv[3], "rb")) == NULL) err(1, "fopen(%s)", argv[3]); /* @@ -109,21 +109,21 @@ /* Close patch file and re-open it via libbzip2 at the right places */ if (fclose(f)) err(1, "fclose(%s)", argv[3]); - if ((cpf = fopen(argv[3], "r")) == NULL) + if ((cpf = fopen(argv[3], "rb")) == NULL) err(1, "fopen(%s)", argv[3]); if (fseeko(cpf, 32, SEEK_SET)) err(1, "fseeko(%s, %lld)", argv[3], (long long)32); if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL) errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err); - if ((dpf = fopen(argv[3], "r")) == NULL) + if ((dpf = fopen(argv[3], "rb")) == NULL) err(1, "fopen(%s)", argv[3]); if (fseeko(dpf, 32 + bzctrllen, SEEK_SET)) err(1, "fseeko(%s, %lld)", argv[3], (long long)(32 + bzctrllen)); if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL) errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err); - if ((epf = fopen(argv[3], "r")) == NULL) + if ((epf = fopen(argv[3], "rb")) == NULL) err(1, "fopen(%s)", argv[3]); if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET)) err(1, "fseeko(%s, %lld)", argv[3], @@ -131,7 +131,7 @@ if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL) errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err); - if(((fd=open(argv[1],O_RDONLY,0))<0) || + if(((fd=open(argv[1],O_RDONLY|O_BINARY,0))<0) || ((oldsize=lseek(fd,0,SEEK_END))==-1) || ((old=malloc(oldsize+1))==NULL) || (lseek(fd,0,SEEK_SET)!=0) || @@ -192,7 +192,7 @@ err(1, "fclose(%s)", argv[3]); /* Write the new file */ - if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) || + if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666))<0) || (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) err(1,"%s",argv[2]); >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200612050528.kB55SQt7020756>