Page MenuHomeFreeBSD

xargs: Limit -n to {ARG_MAX}
ClosedPublic

Authored by des on Jul 25 2025, 6:58 PM.
Tags
None
Referenced Files
F166349971: D51536.id159228.diff
Thu, Aug 13, 1:37 AM
F166333593: D51536.id159133.diff
Wed, Aug 12, 11:36 PM
F166293051: D51536.id159126.diff
Wed, Aug 12, 5:22 PM
Unknown Object (File)
Mon, Aug 10, 12:15 PM
Unknown Object (File)
Mon, Aug 10, 11:09 AM
Unknown Object (File)
Mon, Aug 10, 7:35 AM
Unknown Object (File)
Sun, Aug 9, 12:47 PM
Unknown Object (File)
Sat, Aug 8, 2:38 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 Skipped
Unit
Tests Skipped
Build Status
Buildable 65728
Build 62611: arc lint + arc unit

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.