From 01fd555e852eea9ccdc4ced9f51b60de25d64ed3 Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Wed, 18 Feb 2015 16:01:36 -0500 Subject: [PATCH] main: fix infinite loop in arguments parsing Refs #65931 Change-Id: I1753fc6bf9206325c97303d535ba1e2795c823b4 --- daemon/bin/main.cpp | 9 +++++++-- daemon/bin/osxmain.cpp | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/daemon/bin/main.cpp b/daemon/bin/main.cpp index 83a40182c8..145f8e0f1f 100644 --- a/daemon/bin/main.cpp +++ b/daemon/bin/main.cpp @@ -85,7 +85,13 @@ parse_args(int argc, char *argv[], bool& persistent) /* getopt_long stores the option index here. */ int option_index = 0; - switch (getopt_long(argc, argv, "dcphv", long_options, &option_index)) { + auto c = getopt_long(argc, argv, "dcphv", long_options, &option_index); + + // end of the options + if (c == -1) + break; + + switch (c) { case 'd': debugFlag = true; break; @@ -107,7 +113,6 @@ parse_args(int argc, char *argv[], bool& persistent) versionFlag = true; break; - case -1: // end of the options default: break; } diff --git a/daemon/bin/osxmain.cpp b/daemon/bin/osxmain.cpp index e0a24d966c..1a75236238 100644 --- a/daemon/bin/osxmain.cpp +++ b/daemon/bin/osxmain.cpp @@ -90,7 +90,13 @@ parse_args(int argc, char *argv[], bool& persistent) /* getopt_long stores the option index here. */ int option_index = 0; - switch (getopt_long(argc, argv, "dcphv", long_options, &option_index)) { + auto c = getopt_long(argc, argv, "dcphv", long_options, &option_index); + + // end of the options + if (c == -1) + break; + + switch (c) { case 'd': debugFlag = true; break; @@ -112,7 +118,6 @@ parse_args(int argc, char *argv[], bool& persistent) versionFlag = true; break; - case -1: // end of the options default: break; } -- GitLab