Page MenuHomeFreeBSD

xargs: Limit -n to {ARG_MAX}
ClosedPublic

Authored by des on Jul 25 2025, 6:58 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Sep 14, 12:49 AM
Unknown Object (File)
Sat, Sep 13, 2:54 AM
Unknown Object (File)
Sat, Sep 13, 2:45 AM
Unknown Object (File)
Fri, Sep 12, 7:33 AM
Unknown Object (File)
Fri, Sep 5, 7:32 PM
Unknown Object (File)
Sun, Aug 31, 2:24 PM
Unknown Object (File)
Aug 7 2025, 7:20 PM
Unknown Object (File)
Aug 7 2025, 7:20 PM
Subscribers

Details

Summary

Since it's not possible to pass more than {ARG_MAX} bytes on the command
line, it's also not possible to pass more than {ARG_MAX} individual
arguments. Therefore, {ARG_MAX} is a reasonable upper bound for the -n
option. This resolves both the arithmetic overflow issue and the CI OOM
issue, so we can safely re-enable the test.

Fixes: eab91d008165
Fixes: 2682a1552724
MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

des requested review of this revision.Jul 25 2025, 6:58 PM

seems reasonable

usr.bin/xargs/tests/regress.sh
15–16

since the filename is fixed as n524288.out anyway it seems using $(()) is an unnecessary minor obfuscation

This revision is now accepted and ready to land.Jul 25 2025, 7:24 PM
des marked an inline comment as done.Jul 25 2025, 7:26 PM
des added inline comments.
usr.bin/xargs/tests/regress.sh
15–16

it gets dropped in D51537

des marked an inline comment as done.Jul 25 2025, 7:28 PM
des added inline comments.
usr.bin/xargs/tests/regress.sh
15–16

the reason for it btw is that's how ARG_MAX is defined in sys/sys/syslimits.h:

#define	ARG_MAX	      (2 * 256 * 1024)	/* max bytes for an exec function */

Thank you! Seems reasonable.

{ARG_MAX} is variable, don't hardcode it

This revision now requires review to proceed.Jul 25 2025, 7:53 PM
This revision is now accepted and ready to land.Jul 25 2025, 7:58 PM
This revision was automatically updated to reflect the committed changes.