xargs: Prevent overflow in linelen calculation if nargs is large.
MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D41023
This commit is contained in:
parent
1048a870e3
commit
eab91d0081
1
usr.bin/xargs/tests/regress.n2147483647.out
Normal file
1
usr.bin/xargs/tests/regress.n2147483647.out
Normal file
@ -0,0 +1 @@
|
|||||||
|
quick brown fox jumped over the lazy dog
|
@ -5,6 +5,7 @@ echo 1..21
|
|||||||
REGRESSION_START($1)
|
REGRESSION_START($1)
|
||||||
|
|
||||||
REGRESSION_TEST(`normal', `xargs echo The <${SRCDIR}/regress.in')
|
REGRESSION_TEST(`normal', `xargs echo The <${SRCDIR}/regress.in')
|
||||||
|
REGRESSION_TEST(`n2147483647', `xargs -n2147483647 <${SRCDIR}/regress.in')
|
||||||
REGRESSION_TEST(`I', `xargs -I% echo The % % % %% % % <${SRCDIR}/regress.in')
|
REGRESSION_TEST(`I', `xargs -I% echo The % % % %% % % <${SRCDIR}/regress.in')
|
||||||
REGRESSION_TEST(`J', `xargs -J% echo The % again. <${SRCDIR}/regress.in')
|
REGRESSION_TEST(`J', `xargs -J% echo The % again. <${SRCDIR}/regress.in')
|
||||||
REGRESSION_TEST(`L', `xargs -L3 echo <${SRCDIR}/regress.in')
|
REGRESSION_TEST(`L', `xargs -L3 echo <${SRCDIR}/regress.in')
|
||||||
|
@ -257,7 +257,7 @@ main(int argc, char *argv[])
|
|||||||
* the maximum arguments to be read from stdin and the trailing
|
* the maximum arguments to be read from stdin and the trailing
|
||||||
* NULL.
|
* NULL.
|
||||||
*/
|
*/
|
||||||
linelen = 1 + argc + nargs + 1;
|
linelen = 1 + argc + (size_t)nargs + 1;
|
||||||
if ((av = bxp = malloc(linelen * sizeof(char *))) == NULL)
|
if ((av = bxp = malloc(linelen * sizeof(char *))) == NULL)
|
||||||
errx(1, "malloc failed");
|
errx(1, "malloc failed");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user