Page MenuHomeFreeBSD

pkill: use an ARG_MAX size buffer for argument matching
ClosedPublic

Authored by kevans on Feb 18 2023, 4:06 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 11, 3:23 PM
Unknown Object (File)
Thu, Apr 11, 3:03 PM
Unknown Object (File)
Wed, Apr 10, 12:18 AM
Unknown Object (File)
Mon, Apr 8, 10:07 PM
Unknown Object (File)
Thu, Apr 4, 11:59 AM
Unknown Object (File)
Mar 19 2024, 1:22 AM
Unknown Object (File)
Mar 11 2024, 5:36 PM
Unknown Object (File)
Mar 11 2024, 5:35 PM

Details

Summary

Right now pkill/pgrep cut off at _POSIX2_LINE_MAX (2048), but argument
strings can be much larger (ARG_MAX is 256K/512K). Stop arbitrarily
cutting the search off at 2K, rather than documenting the limit.

Sponsored by: Klara, Inc.

Diff Detail

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

Event Timeline

allanjude added a subscriber: allanjude.

Reviewed by: allanjude

This revision is now accepted and ready to land.Feb 28 2023, 2:52 AM
des added inline comments.
bin/pkill/pkill.c
393

The first half of this is meaningless since we grow the buffer.

403

Is there a possibility that this is still less than jsz + arglen? Perhaps use roundup(jsz + arglen, DFLT_BUF_SIZE) instead?

bin/pkill/tests/pgrep-f_test.sh
24

s/one/once/

des requested changes to this revision.Feb 28 2023, 10:47 AM
This revision now requires changes to proceed.Feb 28 2023, 10:47 AM
bin/pkill/pkill.c
66

Not needed.

153
408
bin/pkill/pkill.c
403

btw if you do this you can also skip the initiall calloc() and just initialize buf to NULL and bufsz to 0, drop MAX_BUF_INCREMENT and rename DFLT_BUF_SIZE to BUF_INCREMENT; also, the comment immediately above this becomes moot.

bin/pkill/pkill.c
403

I'm toying with the idea of just allocating an ARG_MAX * 2 buffer if we're doing arg matching and dropping this realloc business; should be a 1MB buffer on FreeBSD and easily handle everything.

Can't quite initialize buf to NULL because it's reused elsewhere earlier in the code at the moment for error strings

bin/pkill/pkill.c
403

That works too but in that case I would use malloc(), not calloc().

kevans retitled this revision from pkill: use a dynamic buffer to allow for searching longer arguments to pkill: use an ARG_MAX size buffer for argument matching.Mar 17 2023, 4:48 AM

Switch to a fixed ARG_MAX * 2 buffer instead of complicating it with realloc()

s/1/STATUS_ERROR/ per review comment

This revision is now accepted and ready to land.Mar 18 2023, 4:54 PM