Skip to content

Commit

Permalink
libsubprocess: check that bufsize > 0
Browse files Browse the repository at this point in the history
Problem: A channel bufsize setting of 0 is technically possible,
which should not be allowed.

Check for bufsize > 0.  Add unit test.
  • Loading branch information
chu11 committed Oct 11, 2024
1 parent 4025515 commit 0482fd6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/common/libsubprocess/test/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ void test_bufsize_error (flux_reactor_t *r)
char *av[] = { "/bin/true", NULL };
flux_cmd_t *cmd;
flux_subprocess_t *p = NULL;
flux_subprocess_ops_t ops = {
.on_completion = completion_cb,
.on_channel_out = subprocess_standard_output,
.on_stdout = subprocess_standard_output,
.on_stderr = subprocess_standard_output
};

ok ((cmd = flux_cmd_create (1, av, NULL)) != NULL, "flux_cmd_create");

Expand All @@ -439,18 +445,27 @@ void test_bufsize_error (flux_reactor_t *r)
ok (flux_cmd_setopt (cmd, "TEST_CHANNEL_BUFSIZE", "ABCD") == 0,
"flux_cmd_setopt set TEST_CHANNEL_BUFSIZE success");

flux_subprocess_ops_t ops = {
.on_completion = completion_cb,
.on_channel_out = subprocess_standard_output,
.on_stdout = subprocess_standard_output,
.on_stderr = subprocess_standard_output
};
p = flux_local_exec (r, 0, cmd, &ops);
ok (p == NULL
&& errno == EINVAL,
"flux_local_exec fails with EINVAL due to bad bufsize input");

flux_cmd_destroy (cmd);

ok ((cmd = flux_cmd_create (1, av, NULL)) != NULL, "flux_cmd_create");

ok (flux_cmd_add_channel (cmd, "TEST_CHANNEL") == 0,
"flux_cmd_add_channel success adding channel TEST_CHANNEL");

ok (flux_cmd_setopt (cmd, "TEST_CHANNEL_BUFSIZE", "0") == 0,
"flux_cmd_setopt set TEST_CHANNEL_BUFSIZE success");

p = flux_local_exec (r, 0, cmd, &ops);
ok (p == NULL
&& errno == EINVAL,
"flux_local_exec fails with EINVAL due to bufsize zero");

flux_cmd_destroy (cmd);
}

int main (int argc, char *argv[])
Expand Down
4 changes: 4 additions & 0 deletions src/common/libsubprocess/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ int cmd_option_bufsize (flux_subprocess_t *p, const char *name)
uint64_t size;
if (parse_size (val, &size) < 0)
goto cleanup;
if (size == 0) {
errno = EINVAL;
goto cleanup;
}
if (size > INT_MAX) {
errno = EOVERFLOW;
goto cleanup;
Expand Down

0 comments on commit 0482fd6

Please sign in to comment.