Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F166828208
D7861.id20315.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D7861.id20315.diff
View Options
Index: usr.bin/bsdiff/bspatch/bspatch.c
===================================================================
--- usr.bin/bsdiff/bspatch/bspatch.c
+++ usr.bin/bsdiff/bspatch/bspatch.c
@@ -44,6 +44,7 @@
#include <fcntl.h>
#include <libgen.h>
#include <limits.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -105,8 +106,7 @@
u_char *old, *new;
off_t oldpos, newpos;
off_t ctrl[3];
- off_t lenread;
- off_t i;
+ off_t i, lenread, offset;
#ifdef HAVE_CAPSICUM
cap_rights_t rights_dir, rights_ro, rights_wr;
#endif
@@ -179,9 +179,10 @@
from oldfile to x bytes from the diff block; copy y bytes from the
extra block; seek forwards in oldfile by z bytes".
*/
+ _Static_assert(sizeof(header) == 32, "header size must be 32");
/* Read header */
- if (fread(header, 1, 32, f) < 32) {
+ if (fread(header, 1, sizeof(header), f) < sizeof(header)) {
if (feof(f))
errx(1, "Corrupt patch");
err(1, "fread(%s)", argv[3]);
@@ -195,27 +196,29 @@
bzctrllen = offtin(header + 8);
bzdatalen = offtin(header + 16);
newsize = offtin(header + 24);
- if (bzctrllen < 0 || bzctrllen > OFF_MAX - 32 ||
- bzdatalen < 0 || bzctrllen + 32 > OFF_MAX - bzdatalen ||
+ if (bzctrllen < 0 ||
+ bzctrllen > (off_t)(OFF_MAX - sizeof(header)) ||
+ bzdatalen < 0 ||
+ (off_t)(bzctrllen + sizeof(header)) > OFF_MAX - bzdatalen ||
newsize < 0 || newsize > SSIZE_MAX)
errx(1, "Corrupt patch");
/* Close patch file and re-open it via libbzip2 at the right places */
if (fclose(f))
err(1, "fclose(%s)", argv[3]);
- if (fseeko(cpf, 32, SEEK_SET))
- err(1, "fseeko(%s, %lld)", argv[3],
- (long long)32);
+ offset = sizeof(header);
+ if (fseeko(cpf, offset, SEEK_SET))
+ err(1, "fseeko(%s, %jd)", argv[3], (intmax_t)offset);
if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err);
- if (fseeko(dpf, 32 + bzctrllen, SEEK_SET))
- err(1, "fseeko(%s, %lld)", argv[3],
- (long long)(32 + bzctrllen));
+ offset += bzctrllen;
+ if (fseeko(dpf, offset, SEEK_SET))
+ err(1, "fseeko(%s, %jd)", argv[3], (intmax_t)offset);
if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err);
- if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET))
- err(1, "fseeko(%s, %lld)", argv[3],
- (long long)(32 + bzctrllen + bzdatalen));
+ offset += bzdatalen;
+ if (fseeko(epf, offset, SEEK_SET))
+ err(1, "fseeko(%s, %jd)", argv[3], (intmax_t)offset);
if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Aug 17, 9:35 PM (4 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36874850
Default Alt Text
D7861.id20315.diff (2 KB)
Attached To
Mode
D7861: bspatch: use sizeof(header) rather than hardcoded size
Attached
Detach File
Event Timeline
Log In to Comment