gptfdisk: fix stack overflow in parsing cmdline
The getopt_long will return -1 when all command-line
options have been parsed, and the index value will not
be changed in that case.
The caller should check both and handle it properly.
BUG: 64235252
Change-Id: I203dd5bc42bb7ce83e558f25074c7e1a92f250e9
(cherry picked from commit 69e46b9a1cd70aa92fefb3d7a8738c6876df4659)
diff --git a/android_popt.cc b/android_popt.cc
index a1492c6..b5b7970 100644
--- a/android_popt.cc
+++ b/android_popt.cc
@@ -98,7 +98,7 @@
#ifdef LOCAL_DEBUG
fprintf(stderr, "getopt_long()=%c\n", res);
#endif
- if (res == 0 || res == '?') {
+ if (res <= 0 || res == '?' || i == -1) {
return -1;
}