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
4 changes: 2 additions & 2 deletions include/lsof.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ enum lsof_error lsof_logic_and(struct lsof_context *ctx);
*
* You can call this function multiple times to add more search conditions.
*
* \return LSOF_ERROR_INVALID_ARGUMENT if ctx is NULL or frozen, command is
* both included and excluded, or command exceeds the system's supported length
* \return LSOF_ERROR_INVALID_ARGUMENT if ctx is NULL or frozen, command is NULL
* or both included and excluded, or command exceeds the system's supported length
*
* \since API version 1
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/lsof.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ enum lsof_error lsof_select_process(struct lsof_context *ctx, char *command,
char *cp; /* command copy */
MALLOC_S len;
struct str_lst *lpt, *str;
if (!ctx || ctx->frozen) {
if (!ctx || !command || ctx->frozen) {
return LSOF_ERROR_INVALID_ARGUMENT;
}

Expand Down
7 changes: 6 additions & 1 deletion tests/LTnull.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ int main(void) {
failed |= expect_invalid("gather(ctx, NULL)", lsof_gather(ctx, NULL));
failed |= expect_invalid("select_process_regex(ctx, NULL)",
lsof_select_process_regex(ctx, NULL));
failed |= expect_invalid("select_process(ctx, NULL, 0)",
lsof_select_process(ctx, NULL, 0));
failed |= expect_invalid("select_process(ctx, NULL, 1)",
lsof_select_process(ctx, NULL, 1));
/* Rejected arguments must not freeze or otherwise invalidate the context. */
if (lsof_select_pid(ctx, 1, 0) != LSOF_SUCCESS ||
lsof_select_pgid(ctx, 1, 0) != LSOF_SUCCESS ||
lsof_select_process_regex(ctx, "/test/") != LSOF_SUCCESS) {
lsof_select_process_regex(ctx, "/test/") != LSOF_SUCCESS ||
lsof_select_process(ctx, "test", 0) != LSOF_SUCCESS) {
fprintf(stderr, "context is unusable after rejected arguments\n");
failed = 1;
}
Expand Down
Loading