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)
Sat, Nov 9, 2:32 PM
Unknown Object (File)
Thu, Nov 7, 10:11 AM
Unknown Object (File)
Oct 1 2024, 3:50 AM
Unknown Object (File)
Sep 23 2024, 6:25 PM
Unknown Object (File)
Sep 19 2024, 7:27 PM
Unknown Object (File)
Sep 19 2024, 10:38 AM
Unknown Object (File)
Sep 19 2024, 4:56 AM
Unknown Object (File)
Sep 16 2024, 4:05 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