← Commit list

b5fc51198

Denys Vlasenko
Denys Vlasenko
2013-02-07
SUCCESS Duration: 196s

Subject

vasprintf: do not use xmalloc, it will deadlock on OOM

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

libbb/platform.c+5 -3
@@ -28,14 +28,16 @@ int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p)
r = vsnprintf(buf, 128, format, p);
va_end(p);
+ /* Note: can't use xstrdup/xmalloc, they call vasprintf (us) on failure! */
+
if (r < 128) {
va_end(p2);
- *string_ptr = xstrdup(buf);
+ *string_ptr = strdup(buf);
return r;
}
- *string_ptr = xmalloc(r+1);
- r = vsnprintf(*string_ptr, r+1, format, p2);
+ *string_ptr = malloc(r+1);
+ r = (*string_ptr ? vsnprintf(*string_ptr, r+1, format, p2) : -1);
va_end(p2);
return r;