Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ DIALECT_NEUTRAL_TESTS = tests/case-00-hello.bash \
tests/case-20-handle-missing-files.bash \
tests/case-20-offset-field.bash \
tests/case-20-repeat-count.bash \
tests/case-20-uid-empty-entry.bash \
tests/case-21-exit-Q-status.bash \
tests/case-22-empty-process-name.bash \
tests/case-23-multi-address-hostname.bash \
Expand Down
13 changes: 12 additions & 1 deletion src/arg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@ int enter_uid(struct lsof_context *ctx, /* context */
char *s, *st;
uid_t uid;

if (!us) {
if (!us || !*us) {
(void)fprintf(stderr, "%s: no UIDs specified\n", Pn);
return (1);
}
Expand Down Expand Up @@ -2063,6 +2063,17 @@ int enter_uid(struct lsof_context *ctx, /* context */
s++;
if (j)
continue;
if (!lnml) {

/*
* An empty entry (e.g. from ",99" or "^") would otherwise be
* taken as UID 0.
*/
(void)fprintf(stderr, "%s: empty -u UID or login name: ", Pn);
safestrprt(us, stderr, 1);
err = 1;
continue;
}
if (nn) {
lnm[lnml++] = '\0';
if ((pw = getpwnam(lnm)) == NULL) {
Expand Down
19 changes: 19 additions & 0 deletions tests/case-20-uid-empty-entry.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# An empty entry in a -u list must not be taken as UID 0.
source tests/common.bash

{
for spec in "" ",99999" "^"; do
output=$($lsof -u "$spec" -F u 2>/dev/null)
status=$?
if echo "$output" | grep -q '^u0$'; then
echo "lsof -u $spec selected UID 0" >> $report
exit 1
fi
if [ $status -eq 0 ]; then
echo "lsof -u $spec should fail" >> $report
exit 1
fi
done
exit 0
} > $report 2>&1
Loading