summaryrefslogtreecommitdiff
path: root/libbb/platform.c
diff options
context:
space:
mode:
authorDenys Vlasenko2013-02-07 16:06:54 +0100
committerDenys Vlasenko2013-02-07 16:06:54 +0100
commitb5fc51198bf451885e6411bae9b25890a5b6fbe2 (patch)
treebd7f73b6fee12c29f896d5a126622de005ca2c89 /libbb/platform.c
parentba76b7a40b929878833731f76306b1c977cc8650 (diff)
downloadbusybox-b5fc51198bf451885e6411bae9b25890a5b6fbe2.zip
busybox-b5fc51198bf451885e6411bae9b25890a5b6fbe2.tar.gz
vasprintf: do not use xmalloc, it will deadlock on OOM
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/platform.c')
-rw-r--r--libbb/platform.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/libbb/platform.c b/libbb/platform.c
index 2bf34f5..d241d25 100644
--- a/libbb/platform.c
+++ b/libbb/platform.c
@@ -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;