Skip to content

Commit f1c8fff

Browse files
Tomasz Żyjewskisbabic
authored andcommitted
/core/swupdate.c: dynamic memory allocation for downloader, suricatta and webserver options
This patch allows to input data for downloader, suricatta and webserver options with no restrictions in data length. It was created with help of the comments contained in conversation. [1] [1] https://groups.google.com/forum/#!searchin/swupdate/%5Bswupdate%5D$20%5BPATCH%5D$20Extend$20maximal$20length$20of$20command$20line$20arguments%7Csort:date/swupdate/txB_qjAK8Fc/ZeoLMV_ECwAJ Signed-off-by: Tomasz Żyjewski <[email protected]>
1 parent f811c91 commit f1c8fff

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

core/swupdate.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,19 +586,19 @@ int main(int argc, char **argv)
586586
int result = EXIT_SUCCESS;
587587
#ifdef CONFIG_SURICATTA
588588
int opt_u = 0;
589-
char suricattaoptions[1024];
589+
char *suricattaoptions;
590590
char **argvalues = NULL;
591591
int argcount = 0;
592592
#endif
593593
#ifdef CONFIG_WEBSERVER
594594
int opt_w = 0;
595-
char weboptions[1024];
595+
char *weboptions;
596596
char **av = NULL;
597597
int ac = 0;
598598
#endif
599599
#ifdef CONFIG_DOWNLOAD
600600
int opt_d = 0;
601-
char dwloptions[1024];
601+
char *dwloptions;
602602
#endif
603603
char **dwlav = NULL;
604604
int dwlac = 0;
@@ -772,9 +772,14 @@ int main(int argc, char **argv)
772772
break;
773773
#ifdef CONFIG_DOWNLOAD
774774
case 'd':
775-
(void)snprintf(dwloptions, sizeof(dwloptions), "%s %s", argv[0], optarg);
775+
if (asprintf(&dwloptions,"%s %s", argv[0], optarg) ==
776+
ENOMEM_ASPRINTF) {
777+
ERROR("Cannot allocate memory for downloader options.");
778+
exit(EXIT_FAILURE);
779+
}
776780
dwlav = splitargs(dwloptions, &dwlac);
777781
opt_d = 1;
782+
free(dwloptions);
778783
break;
779784
#endif
780785
case 'H':
@@ -783,16 +788,26 @@ int main(int argc, char **argv)
783788
break;
784789
#ifdef CONFIG_SURICATTA
785790
case 'u':
786-
(void)snprintf(suricattaoptions, sizeof(suricattaoptions), "%s %s", argv[0], optarg);
791+
if (asprintf(&suricattaoptions,"%s %s", argv[0], optarg) ==
792+
ENOMEM_ASPRINTF) {
793+
ERROR("Cannot allocate memory for suricatta options.");
794+
exit(EXIT_FAILURE);
795+
}
787796
argvalues = splitargs(suricattaoptions, &argcount);
788797
opt_u = 1;
798+
free(suricattaoptions);
789799
break;
790800
#endif
791801
#ifdef CONFIG_WEBSERVER
792802
case 'w':
793-
snprintf(weboptions, sizeof(weboptions), "%s %s", argv[0], optarg);
803+
if (asprintf(&weboptions,"%s %s", argv[0], optarg) ==
804+
ENOMEM_ASPRINTF) {
805+
ERROR("Cannot allocate memory for webserver options.");
806+
exit(EXIT_FAILURE);
807+
}
794808
av = splitargs(weboptions, &ac);
795809
opt_w = 1;
810+
free(weboptions);
796811
break;
797812
#endif
798813
case 'c':

0 commit comments

Comments
 (0)