Fix segfault calling YGJNILogFunc (#1344)
Summary: X-link: https://github.com/facebook/react-native/pull/39051 Pull Request resolved: https://github.com/facebook/yoga/pull/1344 `YGJNILogFunc` has a bug where it uses a `va_list` to determine the length of a printf string, then reuses the same `va_list` later after it has already been iterated through. Even if no arguments are present, this may cause a crash looking something like: ``` C [libsystem_platform.dylib+0xf12] _platform_strlen+0x12 C [libsystem_c.dylib+0x31bf] __vfprintf+0x1339 C [libsystem_c.dylib+0x307ce] _vsnprintf+0x100 C [libsystem_c.dylib+0x6965] vsnprintf+0x44 C [libyoga.dylib+0x5161] YGJNILogFunc(YGConfig*, YGNode*, YGLogLevel, void*, char const*, __va_list_tag*)+0x59 ``` Fixing this fixes crashing unit tests which are not explicitly disabled. Reviewed By: yungsters Differential Revision: D48388548 fbshipit-source-id: 492e7a89aeb5f9d15485ce31641875a295356bef
This commit is contained in:
committed by
Facebook GitHub Bot
parent
910adaa5dc
commit
38ad93c87b
@@ -139,7 +139,9 @@ static int YGJNILogFunc(
|
||||
void* /*layoutContext*/,
|
||||
const char* format,
|
||||
va_list args) {
|
||||
int result = vsnprintf(NULL, 0, format, args);
|
||||
va_list argsCopy;
|
||||
va_copy(argsCopy, args);
|
||||
int result = vsnprintf(nullptr, 0, format, argsCopy);
|
||||
std::vector<char> buffer(1 + result);
|
||||
vsnprintf(buffer.data(), buffer.size(), format, args);
|
||||
|
||||
|
Reference in New Issue
Block a user