[PATCH] D40053: [asan] Don't crash on fclose(NULL)
Kuba (Brecka) Mracek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 15:21:04 PST 2017
kubamracek created this revision.
kubamracek added a project: Sanitizers.
It's explicitly forbidden to call `fclose` with `NULL`, but at least on Darwin, this succeeds and doesn't segfault. To maintain binary compatibility, ASan should survice `fclose(NULL)` as well.
Repository:
rL LLVM
https://reviews.llvm.org/D40053
Files:
lib/sanitizer_common/sanitizer_common_interceptors.inc
test/asan/TestCases/Darwin/fclose.c
Index: test/asan/TestCases/Darwin/fclose.c
===================================================================
--- test/asan/TestCases/Darwin/fclose.c
+++ test/asan/TestCases/Darwin/fclose.c
@@ -0,0 +1,13 @@
+// RUN: %clang_asan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, const char * argv[]) {
+ fclose(NULL);
+ fprintf(stderr, "Finished.\n");
+ return 0;
+}
+
+// CHECK: Finished.
Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -273,7 +273,7 @@
MetadataHashMap::Handle h(interceptor_metadata_map, (uptr)addr,
/* remove */ false,
/* create */ false);
- if (h.exists()) {
+ if (addr && h.exists()) {
CHECK(!h.created());
CHECK(h->type == CommonInterceptorMetadata::CIMT_FILE);
return &h->file;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40053.122927.patch
Type: text/x-patch
Size: 1047 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171114/2a2de8e3/attachment.bin>
More information about the llvm-commits
mailing list