File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -183,8 +183,16 @@ class _RedisClient {
183183 size_t _sum (T x, const Ts&...xs) {
184184 return x + _sum (xs...);
185185 }
186- char * ibuf () { return _xbuf; }
187- char * obuf () { return _xbuf + _bufsize; }
186+ // _xbuf is a GCC zero-length flex-array; the actual storage lives in the
187+ // derived class __RedisClient<BUF_SIZE>::_buf. Under -D_FORTIFY_SOURCE>=1,
188+ // __builtin_object_size(_xbuf, *) yields 0, causing libc fortified wrappers
189+ // (__snprintf_chk / __memcpy_chk / __memmove_chk) to falsely report
190+ // buffer overflow. Launder the returned pointer through an inline-asm
191+ // "+r" constraint so the optimizer/FORTIFY can no longer associate it
192+ // with the original [0]-sized array, eliminating both the compile-time
193+ // -Wstringop-overflow warning and the runtime buffer-overflow abort.
194+ char * ibuf () { char * p = _xbuf; __asm__ (" " : " +r" (p)); return p; }
195+ char * obuf () { char * p = _xbuf + _bufsize; __asm__ (" " : " +r" (p)); return p; }
188196 std::string_view __getstring (size_t length);
189197 std::string_view __getline ();
190198
You can’t perform that action at this time.
0 commit comments