From 2757a2c9c819fcae3784576aef0c8400c7ad06d7 Mon Sep 17 00:00:00 2001 From: Michael Moss Date: Thu, 4 Jun 2020 23:28:44 +0000 Subject: Make symupload exit with an error code when command-line parsing fails. This should address the issue where some Chrome builds were failing to upload symbols due to a bad command-line flag, but there was no indication of a problem, and no build failure, because symupload was exiting with a success code. BUG=1091387 R=nbilling@google.com, wuwang@google.com Change-Id: I0d7f1a6d689ca5fd37be3abad4c5ebc97f108e50 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2231574 Reviewed-by: Nelson Billing Reviewed-by: Mike Frysinger --- src/tools/linux/symupload/sym_upload.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tools/linux/symupload/sym_upload.cc b/src/tools/linux/symupload/sym_upload.cc index f155eb95..256f73c5 100644 --- a/src/tools/linux/symupload/sym_upload.cc +++ b/src/tools/linux/symupload/sym_upload.cc @@ -111,7 +111,7 @@ Usage(int argc, const char *argv[]) { //============================================================================= static void SetupOptions(int argc, const char *argv[], Options *options) { - extern int optind; + extern int optind, optopt; int ch; constexpr char flag_pattern[] = "u:v:x:p:k:t:c:i:hf?"; @@ -120,7 +120,11 @@ SetupOptions(int argc, const char *argv[], Options *options) { case 'h': case '?': Usage(argc, argv); - exit(0); + // ch might be '?' because getopt found an error while parsing args (as + // opposed to finding "-?" as an arg), in which case optopt is set to + // the bad arg value, so return an error code if optopt is set, + // otherwise exit cleanly. + exit(optopt == 0 ? 0 : 1); break; case 'u': options->proxy_user_pwd = optarg; -- cgit v1.2.1