aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbohu <bohu@google.com>2019-02-26 18:25:38 -0800
committerandroid-build-merger <android-build-merger@google.com>2019-02-26 18:25:38 -0800
commita3c5581ff8900624fdffc6537797aa5c0b840c24 (patch)
tree487e46d61c7b740d504a0af4917752fa978bbd29
parentf30e93202029e4fcd8442df7d2876736aa761b8d (diff)
parent7404144dd9888de7f1d0f886c387be6b893bcf19 (diff)
downloadgptfdisk-a3c5581ff8900624fdffc6537797aa5c0b840c24.tar.gz
gptfdisk: fix buffer overrun
am: 7404144dd9 Change-Id: I7eb316c1ee9b5ea3ad056f0b1caacf8858abf28c
-rw-r--r--android_popt.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/android_popt.cc b/android_popt.cc
index b5b7970..98b7f99 100644
--- a/android_popt.cc
+++ b/android_popt.cc
@@ -29,8 +29,10 @@ poptContext poptGetContext(const char *name, int argc, const char **argv,
for (; options[count].longName; count++) {
}
+ // getopt_long expects the last element to be null
+ // so allocate count + 1
struct option *long_options = (struct option *)
- calloc(count, sizeof(struct option));
+ calloc(count + 1, sizeof(struct option));
for (int i = 0; options[i].longName; i++) {
long_options[i].name = options[i].longName;
long_options[i].flag = 0;