Merge branch 'pw/apply-ulong-overflow-check'
"git apply" internally uses unsigned long for line numbers and uses strtoul() to parse numbers on the hunk headers. It however forgot to check parse errors. * pw/apply-ulong-overflow-check: apply: detect overflow when parsing hunk header
This commit is contained in:
3
apply.c
3
apply.c
@ -1423,7 +1423,10 @@ static int parse_num(const char *line, unsigned long *p)
|
|||||||
|
|
||||||
if (!isdigit(*line))
|
if (!isdigit(*line))
|
||||||
return 0;
|
return 0;
|
||||||
|
errno = 0;
|
||||||
*p = strtoul(line, &ptr, 10);
|
*p = strtoul(line, &ptr, 10);
|
||||||
|
if (errno)
|
||||||
|
return 0;
|
||||||
return ptr - line;
|
return ptr - line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,4 +38,17 @@ incomplete (1)
|
|||||||
incomplete (2)
|
incomplete (2)
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'applying a hunk header which overflows fails' '
|
||||||
|
cat >patch <<-\EOF &&
|
||||||
|
diff -u a/file b/file
|
||||||
|
--- a/file
|
||||||
|
+++ b/file
|
||||||
|
@@ -98765432109876543210 +98765432109876543210 @@
|
||||||
|
-a
|
||||||
|
+b
|
||||||
|
EOF
|
||||||
|
test_must_fail git apply patch 2>err &&
|
||||||
|
echo "error: corrupt patch at line 4" >expect &&
|
||||||
|
test_cmp expect err
|
||||||
|
'
|
||||||
test_done
|
test_done
|
||||||
|
Reference in New Issue
Block a user