Repository navigation
Conversation
An empty entry in a -p or -g list, like the first one in "-p ,123", or a lone "^", was entered as ID 0. On Linux, "lsof -p ,123" listed process 123 and exited with 1 because PID 0 was not located, and "lsof -p ^" listed every process. An empty -p list entered no PID at all, so "lsof -p ''" listed every process and exited with 0. Report "empty process ID" or "empty process group ID" for an empty entry, and "no process ID specified" for an empty -p list, like the checks that enter_uid() has for -u. "-g ''" keeps its meaning: Lsof.8 says that -g without a PGID set only enables the PGID display. A trailing comma is still accepted; it never entered an ID.
The test checked only that lsof fails and lists no process. Check also the exit status 1, the empty standard output, and the message of each rejected list. Add the forms that must stay accepted: a plain list, a trailing comma, an exclusion, an explicit ID 0, -g with an empty list, and -g with no list. Take the PGID from lsof and not from ps. BusyBox ps has no -p option, so the -g lists of the test had no PGID there. The new checks follow the test suggested in the review of lsof-org#393.
|
Thanks for the patch. I agree with the core bug fix: an empty entry must not become ID 0. However, I’d like to suggest a slightly different treatment: instead of rejecting empty entries, ignore them. For example:
The same would apply to This still fixes the dangerous ID 0 behavior, but avoids turning lists that are assembled mechanically from comma-separated values into hard errors. A leading, trailing, or doubled comma is a very common artifact of shell scripts; ignoring the empty field seems friendlier than aborting.
The remaining question is what to do when no valid ID remains at all, for example
For The main reason I’m raising this is consistency with #377. #377 currently rejects empty entries in
I don’t want to silently diverge from #377 without deciding this explicitly. Explicit |
Rejecting an empty entry turns a list that a script joined with a leading or doubled comma into a hard error. Skip the entry instead, as suggested in the review of lsof-org#393: "-p ,123" and "-p 123,,456" now select the IDs that are there, and still never ID 0. Lsof.8 says so. -p needs at least one ID, so "-p ''", "-p ," and "-p ^" report "no process ID specified" like -p with no argument. That keeps 'lsof -p "$pids"' with an empty variable from listing every process. -g with no ID keeps its documented meaning and only enables the PGID display.
|
Agreed, ignoring them is friendlier for scripts. 933a4f2 skips empty entries in For the empty list I went with option 1, mostly for the I left |
An empty entry in a
-por-glist gets entered as ID 0, and-p ""selects every process:enter_id()doesn't check that an entry has a digit, so,123,123,,456and a lone^end up as PID or PGID 0. It's not new, 4.99.7 and Debian's 4.99.4 do the same. Empty entries are skipped now, so a list with a stray comma selects the IDs that are in it.-pstill needs at least one ID:-p "",-p ,and-p ^are an error like-pwith no argument, which keepslsof -t -p "$pids"with an empty variable from printing every PID. That's per option, so-p 123 -p "", which used to work, is an error too.-gwith no ID left (-g "",-g ,,-g ^) only turns on the PGID display, which is what Lsof.8 says for-gwithout a PGID set.Lsof.8has a line about empty entries now. Addedtests/case-20-id-empty-entry.bash, it fails before and passes after, andmake checkis clean on Linux.