Skip to content

Commit c40113d

Browse files
committed
init: Remove MAX_ARGS limit
init.c imposes limit of MAX_ARGS command line arguments. If there are more arguments then they are silently ignored. Which is wrong and dangerous, imagine one of those arguments being e.g. --dry-run or --safe. There is no reason to limit the number of the arguments to 32 (the value of MAX_ARGS) declared in init.c. Common limits on the number of arguments are much higher, if any. The arguments are passed in the config file provided to the VM, it's the responsibility of the caller to provide sane arguments. Which means we can lift the limit completely and to allocate `argv' arrays to the exact size needed rather than to the predefined maximum limit. For example, the following command works fine for me with this patch, while printing only the first 31 numbers previously: podman run --runtime krun --rm -t \ docker.io/library/alpine echo $(seq 1 10000) Fixes: #323 Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
1 parent ae25314 commit c40113d

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

init/init.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
#define KRUN_FOOTER_LEN 12
3838
#define CMDLINE_SECRET_PATH "/sfs/secrets/coco/cmdline"
3939
#define CONFIG_FILE_PATH "/.krun_config.json"
40-
#define MAX_ARGS 32
4140
#define MAX_PASS_SIZE 512
4241
#define MAX_TOKENS 16384
4342

@@ -624,10 +623,11 @@ static char **config_parse_args(char *data, jsmntok_t *token)
624623
char **argv;
625624
int len;
626625
int i;
626+
int n_args = token->size;
627627

628-
argv = malloc((MAX_ARGS + 1) * sizeof(char *));
628+
argv = malloc((n_args + 1) * sizeof(char *));
629629

630-
for (i = 0; i < token->size && i < MAX_ARGS; i++) {
630+
for (i = 0; i < n_args; i++) {
631631
targ = &token[i + 1];
632632

633633
value = data + targ->start;
@@ -690,14 +690,20 @@ char **concat_entrypoint_argv(char **entrypoint, char **config_argv)
690690
{
691691
char **argv;
692692
int i, j;
693+
int n_args;
693694

694-
argv = malloc((2 * MAX_ARGS + 1) * sizeof(char *));
695+
for (i = 0; entrypoint[i]; i++)
696+
n_args++;
697+
for (j = 0; config_argv[j]; j++)
698+
n_args++;
695699

696-
for (i = 0; i < MAX_ARGS && entrypoint[i]; i++) {
700+
argv = malloc((n_args + 1) * sizeof(char *));
701+
702+
for (i = 0; entrypoint[i]; i++) {
697703
argv[i] = entrypoint[i];
698704
}
699705

700-
for (j = 0; j < MAX_ARGS && config_argv[j]; i++, j++) {
706+
for (j = 0; config_argv[j]; i++, j++) {
701707
argv[i] = config_argv[j];
702708
}
703709

0 commit comments

Comments
 (0)