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 <mark@chromium.org>
This commit is contained in:
Scott Graham 2016-08-10 12:18:49 -07:00
parent 18a839c810
commit 56b14bceef
2 changed files with 6 additions and 4 deletions

View File

@ -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.

View File

@ -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))