Skip to content

Commit c58f00a

Browse files
mz-pdmslp
authored andcommitted
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 b7ecf07 commit c58f00a

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,14 +623,15 @@ static char **config_parse_args(char *data, jsmntok_t *token)
624623
char **argv;
625624
int len;
626625
int i;
626+
const int n_args = token->size;
627627

628-
argv = malloc((MAX_ARGS + 1) * sizeof(char *));
628+
argv = malloc((n_args + 1) * sizeof(char *));
629629
if (!argv) {
630630
perror("malloc(config_parse_args)");
631631
return NULL;
632632
}
633633

634-
for (i = 0; i < token->size && i < MAX_ARGS; i++) {
634+
for (i = 0; i < n_args; i++) {
635635
targ = &token[i + 1];
636636

637637
value = data + targ->start;
@@ -701,18 +701,24 @@ char **concat_entrypoint_argv(char **entrypoint, char **config_argv)
701701
{
702702
char **argv;
703703
int i, j;
704+
int n_args = 0;
704705

705-
argv = malloc((2 * MAX_ARGS + 1) * sizeof(char *));
706+
for (i = 0; entrypoint[i]; i++)
707+
n_args++;
708+
for (j = 0; config_argv[j]; j++)
709+
n_args++;
710+
711+
argv = malloc((n_args + 1) * sizeof(char *));
706712
if (!argv) {
707713
perror("malloc(concat_entrypoint_argv)");
708714
return NULL;
709715
}
710716

711-
for (i = 0; i < MAX_ARGS && entrypoint[i]; i++) {
717+
for (i = 0; entrypoint[i]; i++) {
712718
argv[i] = entrypoint[i];
713719
}
714720

715-
for (j = 0; j < MAX_ARGS && config_argv[j]; i++, j++) {
721+
for (j = 0; config_argv[j]; i++, j++) {
716722
argv[i] = config_argv[j];
717723
}
718724

0 commit comments

Comments
 (0)