Skip to content

Commit db17594

Browse files
committed
Add macro to disable address safety instrumentation
fasthash_accum_cstring_aligned() uses a technique, found in various strlen() implementations, to detect a string's NUL terminator by reading a word at at time. That triggers failures when testing with "-fsanitize=address", at least with frontend code. To enable using this function anywhere, add a function attribute macro to disable such testing. Reviewed by Jeff Davis Discussion: https://postgr.es/m/CANWCAZbwvp7oUEkbw-xP4L0_S_WNKq-J-ucP4RCNDPJnrakUPw%40mail.gmail.com
1 parent 4b968e2 commit db17594

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/include/c.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@
135135
#define pg_nodiscard
136136
#endif
137137

138+
/*
139+
* This macro will disable address safety instrumentation for a function
140+
* when running with "-fsanitize=address". Think twice before using this!
141+
*/
142+
#if defined(__clang__) || __GNUC__ >= 8
143+
#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize("address")))
144+
#elif __has_attribute(no_sanitize_address)
145+
/* This would work for clang, but it's deprecated. */
146+
#define pg_attribute_no_sanitize_address() __attribute__((no_sanitize_address))
147+
#else
148+
#define pg_attribute_no_sanitize_address()
149+
#endif
150+
138151
/*
139152
* Place this macro before functions that should be allowed to make misaligned
140153
* accesses. Think twice before using it on non-x86-specific code!

src/include/common/hashfn_unstable.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,11 @@ fasthash_accum_cstring_unaligned(fasthash_state *hs, const char *str)
213213
*
214214
* With an aligned pointer, we consume the string a word at a time.
215215
* Loading the word containing the NUL terminator cannot segfault since
216-
* allocation boundaries are suitably aligned.
216+
* allocation boundaries are suitably aligned. To keep from setting
217+
* off alarms with address sanitizers, exclude this function from
218+
* such testing.
217219
*/
220+
pg_attribute_no_sanitize_address()
218221
static inline size_t
219222
fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
220223
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy