aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-02-12 16:00:53 -0800
committerElliott Hughes <enh@google.com>2016-02-12 16:00:53 -0800
commitcac2908b08f517802e719ddafe39f45c85c96a33 (patch)
tree7bea048743bbf54843f6c84493353508c918e4b4
parent9750a77b31f2fc6d548a02b3a9750c2794648fea (diff)
downloadandroid_bionic-cac2908b08f517802e719ddafe39f45c85c96a33.tar.gz
android_bionic-cac2908b08f517802e719ddafe39f45c85c96a33.tar.bz2
android_bionic-cac2908b08f517802e719ddafe39f45c85c96a33.zip
Fix regerror(..., nullptr, 0).
Found by passing a bad regular expression to the Google benchmark code (https://github.com/google/benchmark). Change-Id: I475db71c25706bbf02091b754acabe8254062f3a
-rw-r--r--libc/Android.mk4
-rw-r--r--libc/upstream-netbsd/android/include/netbsd-compat.h11
-rw-r--r--tests/regex_test.cpp11
3 files changed, 19 insertions, 7 deletions
diff --git a/libc/Android.mk b/libc/Android.mk
index 42f717eaf..f2004e165 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -850,7 +850,9 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(libc_upstream_netbsd_src_files)
LOCAL_CFLAGS := \
$(libc_common_cflags) \
- -Wno-sign-compare -Wno-uninitialized \
+ -Wno-sign-compare \
+ -Wno-uninitialized \
+ -Wno-unused-parameter \
-DPOSIX_MISTAKE \
-include netbsd-compat.h \
diff --git a/libc/upstream-netbsd/android/include/netbsd-compat.h b/libc/upstream-netbsd/android/include/netbsd-compat.h
index 8d1c46b22..665d65e00 100644
--- a/libc/upstream-netbsd/android/include/netbsd-compat.h
+++ b/libc/upstream-netbsd/android/include/netbsd-compat.h
@@ -20,17 +20,16 @@
#define _BSD_SOURCE
#define _GNU_SOURCE
-// NetBSD uses _DIAGASSERT to null-check arguments and the like.
-#include <assert.h>
-#define _DIAGASSERT(e) ((e) ? (void) 0 : __assert2(__FILE__, __LINE__, __func__, #e))
-
-// TODO: update our <sys/cdefs.h> to support this properly.
-#define __type_fit(t, a) (0 == 0)
+// NetBSD uses _DIAGASSERT to null-check arguments and the like,
+// but it's clear from the number of mistakes in their assertions
+// that they don't actually test or ship with this.
+#define _DIAGASSERT(e) /* nothing */
// TODO: we don't yet have thread-safe environment variables.
#define __readlockenv() 0
#define __unlockenv() 0
+#include <sys/cdefs.h>
#include <stddef.h>
__LIBC_HIDDEN__ int reallocarr(void*, size_t, size_t);
diff --git a/tests/regex_test.cpp b/tests/regex_test.cpp
index 4a4409ef3..0e7f8dd7f 100644
--- a/tests/regex_test.cpp
+++ b/tests/regex_test.cpp
@@ -46,3 +46,14 @@ TEST(regex, match_offsets) {
ASSERT_EQ(2, matches[0].rm_eo);
regfree(&re);
}
+
+TEST(regex, regerror_NULL_0) {
+ regex_t re;
+ int error = regcomp(&re, "*", REG_EXTENDED);
+ ASSERT_NE(0, error);
+
+ // Passing a null pointer and a size of 0 is a legitimate way to ask
+ // how large a buffer we would need for the error message.
+ int error_length = regerror(error, &re, nullptr, 0);
+ ASSERT_GT(error_length, 0);
+}