From 40ffdfe623c73c3fdba15fd24bd05d206eff7aad Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Fri, 5 Oct 2018 09:45:02 +0300 Subject: apk: fix all_options array size off-by-one merge_options() will write one more entry to the options table which is the end-of-table indicator. Allocate memory for it too. valgrind did not pick it up due to being in stack; changing alloca to malloc would make valgrind notice the issue too. Reported-by: Mobile Stream --- src/apk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/apk.c b/src/apk.c index 071d5ae..f4e510f 100644 --- a/src/apk.c +++ b/src/apk.c @@ -542,7 +542,7 @@ int main(int argc, char **argv) applet = deduce_applet(argc, argv); if (applet && applet->optgroups[0]) optgroups = applet->optgroups; - for (i = 0, num_options = 0; optgroups[i]; i++) + for (i = 0, num_options = 1; optgroups[i]; i++) num_options += optgroups[i]->num_options; all_options = alloca(sizeof(struct option) * num_options); for (i = r = 0; optgroups[i]; r += optgroups[i]->num_options, i++) -- cgit v1.2.3-70-g09d2