Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F115929132
D46169.id141473.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D46169.id141473.diff
View Options
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -203,9 +203,9 @@
static int *member; /* will be overlaid on file[1] */
static int clen;
static int inifdef; /* whether or not we are in a #ifdef block */
-static int len[2];
-static int pref, suff; /* length of prefix and suffix */
-static int slen[2];
+static size_t len[2]; /* lengths of files in lines */
+static size_t pref, suff; /* lengths of prefix and suffix */
+static size_t slen[2]; /* lengths of files minus pref / suff */
static int anychange;
static int hw, lpad,rpad; /* half width and padding */
static int edoffset;
@@ -425,6 +425,10 @@
status |= 1;
goto closem;
}
+ if (len[0] >= INT_MAX - 2)
+ errc(1, EFBIG, "%s", file1);
+ if (len[1] >= INT_MAX - 2)
+ errc(1, EFBIG, "%s", file2);
prune();
sort(sfile[0], slen[0]);
@@ -550,18 +554,17 @@
sz = 100;
p = xcalloc(sz + 3, sizeof(*p));
- while ((r = readhash(fd, flags, &h)) != RH_EOF)
- switch (r) {
- case RH_EOF: /* otherwise clang complains */
- case RH_BINARY:
+ while ((r = readhash(fd, flags, &h)) != RH_EOF) {
+ if (r == RH_BINARY)
return (false);
- case RH_OK:
- if (j == sz) {
- sz = sz * 3 / 2;
- p = xreallocarray(p, sz + 3, sizeof(*p));
- }
- p[++j].value = h;
+ if (j == SIZE_MAX)
+ break;
+ if (j == sz) {
+ sz = sz * 3 / 2;
+ p = xreallocarray(p, sz + 3, sizeof(*p));
}
+ p[++j].value = h;
+ }
len[i] = j;
file[i] = p;
@@ -572,7 +575,7 @@
static void
prune(void)
{
- int i, j;
+ size_t i, j;
for (pref = 0; pref < len[0] && pref < len[1] &&
file[0][pref + 1].value == file[1][pref + 1].value;
@@ -710,7 +713,7 @@
unravel(int p)
{
struct cand *q;
- int i;
+ size_t i;
for (i = 0; i <= len[0]; i++)
J[i] = i <= pref ? i :
@@ -737,7 +740,7 @@
ixold[0] = ixnew[0] = 0;
/* jackpot = 0; */
ctold = ctnew = 0;
- for (i = 1; i <= len[0]; i++) {
+ for (i = 1; i <= (int)len[0]; i++) {
if (J[i] == 0) {
ixold[i] = ctold += skipline(f1);
continue;
@@ -837,7 +840,7 @@
ixnew[j] = ctnew;
j++;
}
- for (; j <= len[1]; j++) {
+ for (; j <= (int)len[1]; j++) {
ixnew[j] = ctnew += skipline(f2);
}
/*
@@ -1504,9 +1507,9 @@
b = d = 0; /* gcc */
lowa = MAX(1, cvp->a - diff_context);
- upb = MIN(len[0], context_vec_ptr->b + diff_context);
+ upb = MIN((int)len[0], context_vec_ptr->b + diff_context);
lowc = MAX(1, cvp->c - diff_context);
- upd = MIN(len[1], context_vec_ptr->d + diff_context);
+ upd = MIN((int)len[1], context_vec_ptr->d + diff_context);
printf("***************");
if (flags & (D_PROTOTYPE | D_MATCHLAST)) {
@@ -1607,9 +1610,9 @@
b = d = 0; /* gcc */
lowa = MAX(1, cvp->a - diff_context);
- upb = MIN(len[0], context_vec_ptr->b + diff_context);
+ upb = MIN((int)len[0], context_vec_ptr->b + diff_context);
lowc = MAX(1, cvp->c - diff_context);
- upd = MIN(len[1], context_vec_ptr->d + diff_context);
+ upd = MIN((int)len[1], context_vec_ptr->d + diff_context);
printf("@@ -");
uni_range(lowa, upb);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, May 1, 1:12 PM (15 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17882119
Default Alt Text
D46169.id141473.diff (3 KB)
Attached To
Mode
D46169: diff: Fix integer overflow.
Attached
Detach File
Event Timeline
Log In to Comment