Skip to content

Commit 6b93c95

Browse files
committed
Fix GH-9068: Conditional jump or move depends on uninitialised value(s)
This patch preserves the scratch registers of the SysV x86-64 ABI by storing them to the stack and restoring them later. We need to do this to prevent the registers of the caller from being corrupted. The reason these get corrupted is because the compiler is unaware of the Valgrind replacement function and thus makes assumptions about the original function regarding registers which are not true for the replacement function. For implementation I used a GCC and Clang attribute. A more general approach would be to use inline assembly but that's also less portable and quite hacky. This attributes is supported since GCC 7.x.
1 parent fbf5216 commit 6b93c95

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Zend/zend_string.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,24 @@ ZEND_API void zend_interned_strings_switch_storage(bool request)
372372
# define I_REPLACE_SONAME_FNNAME_ZU(soname, fnname) _vgr00000ZU_ ## soname ## _ ## fnname
373373
#endif
374374

375-
ZEND_API bool ZEND_FASTCALL I_REPLACE_SONAME_FNNAME_ZU(NONE,zend_string_equal_val)(zend_string *s1, zend_string *s2)
375+
/* See GH-9068 */
376+
#if defined(__GNUC__) && __has_attribute(no_caller_saved_registers)
377+
# define NO_CALLER_SAVED_REGISTERS __attribute__((no_caller_saved_registers))
378+
# pragma GCC push_options
379+
# pragma GCC target ("general-regs-only")
380+
#else
381+
# define NO_CALLER_SAVED_REGISTERS
382+
#endif
383+
384+
ZEND_API bool ZEND_FASTCALL NO_CALLER_SAVED_REGISTERS I_REPLACE_SONAME_FNNAME_ZU(NONE,zend_string_equal_val)(zend_string *s1, zend_string *s2)
376385
{
377386
return !memcmp(ZSTR_VAL(s1), ZSTR_VAL(s2), ZSTR_LEN(s1));
378387
}
379388

389+
#if defined(__GNUC__) && __has_attribute(no_caller_saved_registers)
390+
# pragma GCC pop_options
391+
#endif
392+
380393
#if defined(__GNUC__) && defined(__i386__)
381394
ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *s2)
382395
{

0 commit comments

Comments
 (0)