From 2896506340cee592c9e9645db83af67c5b3093cd Mon Sep 17 00:00:00 2001 From: Matthias Gerstner Date: Mon, 30 Jul 2018 16:43:58 +0200 Subject: [PATCH] cpugovctl: correctly evaluate available command line parameters When calling `cpugovctl set` then an access to the terminating NULL pointer of argv is made. --- daemon/cpugovctl.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/daemon/cpugovctl.c b/daemon/cpugovctl.c index 51b2e58..5aaf1fb 100644 --- a/daemon/cpugovctl.c +++ b/daemon/cpugovctl.c @@ -64,14 +64,9 @@ static void set_gov_state(const char *value) */ int main(int argc, char *argv[]) { - if (argc < 2) { - fprintf(stderr, "usage: cpugovctl [get] [set VALUE]\n"); - return EXIT_FAILURE; - } - - if (strncmp(argv[1], "get", 3) == 0) { + if (argc == 2 && strncmp(argv[1], "get", 3) == 0) { printf("%s", get_gov_state()); - } else if (strncmp(argv[1], "set", 3) == 0) { + } else if (argc == 3 && strncmp(argv[1], "set", 3) == 0) { const char *value = argv[2]; /* Must be root to set the state */ @@ -82,6 +77,7 @@ int main(int argc, char *argv[]) set_gov_state(value); } else { + fprintf(stderr, "usage: cpugovctl [get] [set VALUE]\n"); return EXIT_FAILURE; }