From 56b14bceefcec03fc11b3222c435522922f65640 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Wed, 10 Aug 2016 12:18:49 -0700 Subject: [PATCH] win getopt: memcmp() -> strncmp() for ASan R=mark@chromium.org BUG=chromium:635990 Change-Id: I69f0e1f0f48c6d0d2ac26eb395df7add2907d02b Reviewed-on: https://chromium-review.googlesource.com/367350 Reviewed-by: Mark Mentovai --- third_party/getopt/README.crashpad | 2 ++ third_party/getopt/getopt.cc | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/third_party/getopt/README.crashpad b/third_party/getopt/README.crashpad index 9b2b8321..a7166e1f 100644 --- a/third_party/getopt/README.crashpad +++ b/third_party/getopt/README.crashpad @@ -13,3 +13,5 @@ Local Modifications: - Add copy of copyright (Public domain) to the top of both files for Chromium's checklicenses step. - Compiled as .cc, and wrapped in namespace crashpad. +- memcmp() -> strncmp() in getopt.cc to make ASan happier about some string + manipulation. diff --git a/third_party/getopt/getopt.cc b/third_party/getopt/getopt.cc index 1f6eaffd..137218b9 100644 --- a/third_party/getopt/getopt.cc +++ b/third_party/getopt/getopt.cc @@ -240,11 +240,11 @@ getopt_internal (int argc, char **argv, char *shortopts, /* first, is it a long option? */ if (longopts != NULL - && (memcmp (argv[optind], "--", 2) == 0 + && (strncmp (argv[optind], "--", 2) == 0 || (only && argv[optind][0] == '+')) && optwhere == 1) { /* handle long options */ - if (memcmp (argv[optind], "--", 2) == 0) + if (strncmp (argv[optind], "--", 2) == 0) optwhere = 2; longopt_match = -1; possible_arg = strchr (argv[optind] + optwhere, '='); @@ -259,8 +259,8 @@ getopt_internal (int argc, char **argv, char *shortopts, match_chars = (possible_arg - argv[optind]) - optwhere; for (optindex = 0; longopts[optindex].name != NULL; optindex++) { - if (memcmp (argv[optind] + optwhere, - longopts[optindex].name, match_chars) == 0) + if (strncmp (argv[optind] + optwhere, + longopts[optindex].name, match_chars) == 0) { /* do we have an exact match? */ if (match_chars == strlen (longopts[optindex].name))