From 6804edfc85c96fbda043ef9dd5d90122165bd32a Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 17 Jan 2011 08:39:44 +0000 Subject: Better error checking of argc for --applet call. --- src/rc/rc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/rc/rc.c b/src/rc/rc.c index af346657..14be8683 100644 --- a/src/rc/rc.c +++ b/src/rc/rc.c @@ -821,11 +821,13 @@ main(int argc, char **argv) * than trusting argv[0], as argv[0] is not going to be the applet value if * we are doing SELinux context switching. For this, we allow calls such as * 'rc --applet APPLET', and shift ALL of argv down by two array items. */ - if(strcmp(basename_c(argv[0]), "rc") == 0 && strcmp(argv[1], "--applet") == 0) { - for(i = 2; i < argc; i++) - argv[i-2] = argv[i]; - argv[argc-2] = NULL; - argv[argc-1] = NULL; + if (strcmp(basename_c(argv[0]), "rc") == 0 && argc > 1 && strcmp(argv[1], "--applet") == 0) { + if (argc == 2) + eerrorx("applet argument required"); + for (i = 2; i < argc; i++) + argv[i - 2] = argv[i]; + argv[argc - 2] = NULL; + argv[argc - 1] = NULL; argc -= 2; } /* Now we can trust our applet value in argv[0] */ -- cgit v1.2.3