Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F147485833
D55110.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
D55110.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
@@ -77,6 +77,7 @@
#include <paths.h>
#include <regex.h>
#include <stdbool.h>
+#include <stdckdint.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@@ -1056,7 +1057,7 @@
{
static size_t max_context = 64;
long curpos;
- int i, nc;
+ int dist, i, nc;
const char *walk;
bool skip_blanks, ignore;
@@ -1120,8 +1121,9 @@
*/
print_header(file1, file2);
anychange = 1;
- } else if (a > context_vec_ptr->b + (2 * diff_context) + 1 &&
- c > context_vec_ptr->d + (2 * diff_context) + 1) {
+ } else if (!ckd_add(&dist, diff_context, diff_context) &&
+ a - context_vec_ptr->b - 1 > dist &&
+ c - context_vec_ptr->d - 1 > dist) {
/*
* If this change is more than 'diff_context' lines from the
* previous change, dump the record and reset it.
@@ -1506,10 +1508,14 @@
return;
b = d = 0; /* gcc */
- lowa = MAX(1, cvp->a - diff_context);
- upb = MIN((int)len[0], context_vec_ptr->b + diff_context);
- lowc = MAX(1, cvp->c - diff_context);
- upd = MIN((int)len[1], context_vec_ptr->d + diff_context);
+ if (ckd_sub(&lowa, cvp->a, diff_context) || lowa < 1)
+ lowa = 1;
+ if (ckd_add(&upb, context_vec_ptr->b, diff_context) || upb > (int)len[0])
+ upb = (int)len[0];
+ if (ckd_sub(&lowc, cvp->c, diff_context) || lowc < 1)
+ lowc = 1;
+ if (ckd_add(&upd, context_vec_ptr->d, diff_context) || upd > (int)len[1])
+ upd = (int)len[1];
printf("***************");
if (flags & (D_PROTOTYPE | D_MATCHLAST)) {
@@ -1609,10 +1615,14 @@
return;
b = d = 0; /* gcc */
- lowa = MAX(1, cvp->a - diff_context);
- upb = MIN((int)len[0], context_vec_ptr->b + diff_context);
- lowc = MAX(1, cvp->c - diff_context);
- upd = MIN((int)len[1], context_vec_ptr->d + diff_context);
+ if (ckd_sub(&lowa, cvp->a, diff_context) || lowa < 1)
+ lowa = 1;
+ if (ckd_add(&upb, context_vec_ptr->b, diff_context) || upb > (int)len[0])
+ upb = (int)len[0];
+ if (ckd_sub(&lowc, cvp->c, diff_context) || lowc < 1)
+ lowc = 1;
+ if (ckd_add(&upd, context_vec_ptr->d, diff_context) || upd > (int)len[1])
+ upd = (int)len[1];
printf("@@ -");
uni_range(lowa, upb);
diff --git a/usr.bin/diff/tests/diff_test.sh b/usr.bin/diff/tests/diff_test.sh
--- a/usr.bin/diff/tests/diff_test.sh
+++ b/usr.bin/diff/tests/diff_test.sh
@@ -24,6 +24,7 @@
atf_test_case noderef
atf_test_case ignorecase
atf_test_case dirloop
+atf_test_case verylong
simple_body()
{
@@ -380,6 +381,36 @@
diff -r a b
}
+bigc_head()
+{
+ atf_set "descr" "Context diff with very large context"
+}
+bigc_body()
+{
+ echo $'x\na\ny' >a
+ echo $'x\nb\ny' >b
+ atf_check -s exit:2 -e ignore diff -C$(((1<<31)-1)) a b
+ atf_check -s exit:1 -o match:'--- 1,3 ---' \
+ diff -C$(((1<<31)-2)) a b
+ atf_check -s exit:1 -o match:'--- 1,3 ---' \
+ diff -Astone -C$(((1<<31)-2)) a b
+}
+
+bigu_head()
+{
+ atf_set "descr" "Unified diff with very large context"
+}
+bigu_body()
+{
+ echo $'x\na\ny' >a
+ echo $'x\nb\ny' >b
+ atf_check -s exit:2 -e ignore diff -U$(((1<<31)-1)) a b
+ atf_check -s exit:1 -o match:'^@@ -1,3 \+1,3 @@$' \
+ diff -U$(((1<<31)-2)) a b
+ atf_check -s exit:1 -o match:'^@@ -1,3 \+1,3 @@$' \
+ diff -Astone -U$(((1<<31)-2)) a b
+}
+
atf_init_test_cases()
{
atf_add_test_case simple
@@ -407,4 +438,6 @@
atf_add_test_case noderef
atf_add_test_case ignorecase
atf_add_test_case dirloop
+ atf_add_test_case bigc
+ atf_add_test_case bigu
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 12, 9:03 AM (16 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29574390
Default Alt Text
D55110.diff (3 KB)
Attached To
Mode
D55110: diff: Fix integer overflows in Stone algorithm
Attached
Detach File
Event Timeline
Log In to Comment