Commit ac6a62d
committed
find_script: avoid potential integer overflow
Fixes a Coverity issue:
>>> function_return: Function Perl_delimcpy_no_escape(tmpbuf, tmpbuf + 4096UL, s, bufend, 58, &len) modifies its argument, assigning 2147483647 to len.
3553 s = delimcpy_no_escape(tmpbuf, tmpbuf + sizeof tmpbuf, s, bufend,
3554 ':', &len);
>>> CID 583353: (Perl#1 of 1): Overflowed constant (INTEGER_OVERFLOW)
>>> overflow_const: Expression len + 1, where len is known to be equal to 2147483647, overflows the type of len + 1, which is type int.
3558 if (len + 1 + strlen(scriptname) + MAX_EXT_LEN >= sizeof tmpbuf)
3559 continue; /* don't search dir with too-long name */
If there is not enough available space in tmpbuf, delimcpy_no_escape
sets len to I32_MAX, but the following code does not check for this. (I
believe this case is reachable simply by setting PATH to a huge string.)
Avoid the potential overflow by rewriting
A + B >= C
as
A >= C - B
(Also, make 'len' unsigned (specifically, size_t) to match the type of
sizeof/strlen() and avoid warnings about comparisons between signed and
unsigned integers.)1 parent af22bdc commit ac6a62d
1 file changed
+18
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3410 | 3410 | | |
3411 | 3411 | | |
3412 | 3412 | | |
3413 | | - | |
| 3413 | + | |
3414 | 3414 | | |
3415 | 3415 | | |
3416 | 3416 | | |
| |||
3550 | 3550 | | |
3551 | 3551 | | |
3552 | 3552 | | |
3553 | | - | |
3554 | | - | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
| 3559 | + | |
3555 | 3560 | | |
3556 | 3561 | | |
3557 | 3562 | | |
3558 | | - | |
3559 | | - | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
3560 | 3573 | | |
3561 | 3574 | | |
3562 | 3575 | | |
| |||
0 commit comments