Unverified Commit a7df35ce authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

Curl_memchr: zero length input can't match

Avoids undefined behavior.

Reported-by: Geeknik Labs
parent abbc8457
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
 *                            | (__| |_| |  _ <| |___
 *                             \___|\___/|_| \_\_____|
 *
 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
 * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution. The terms
@@ -44,6 +44,7 @@
void *
Curl_memrchr(const void *s, int c, size_t n)
{
  if(n > 0) {
    const unsigned char *p = s;
    const unsigned char *q = s;

@@ -54,7 +55,7 @@ Curl_memrchr(const void *s, int c, size_t n)
        return (void *)p;
      p--;
    }

  }
  return NULL;
}