diff options
| author | Felix Fietkau | 2024-01-26 20:00:14 +0000 |
|---|---|---|
| committer | Felix Fietkau | 2024-01-26 20:00:17 +0000 |
| commit | c1be505732e6d254464973bdeacb955214c76c46 (patch) | |
| tree | 0a6768281fec9edead7ae2bea43b445b59158cb1 | |
| parent | 6339204c212b2c3506554a8842030df5ec6fe9c6 (diff) | |
| download | libubox-c1be505732e6d254464973bdeacb955214c76c46.tar.gz | |
udebug: fix crash in udebug_entry_vprintf with longer strings
The passed va_list ap cannot be used more than once. In order to deal with
vsprintf retry, it needs to be copied first. Fixes a procd crash observed
on several platforms.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
| -rw-r--r-- | udebug.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -610,6 +610,7 @@ int udebug_entry_vprintf(struct udebug_buf *buf, const char *fmt, va_list ap) struct udebug_ptr *ptr; uint32_t ofs; uint32_t len; + va_list ap2; char *str; if (!hdr) @@ -621,7 +622,9 @@ int udebug_entry_vprintf(struct udebug_buf *buf, const char *fmt, va_list ap) return -1; str = udebug_buf_alloc(buf, ofs, UDEBUG_MIN_ALLOC_LEN); - len = vsnprintf(str, UDEBUG_MIN_ALLOC_LEN, fmt, ap); + va_copy(ap2, ap); + len = vsnprintf(str, UDEBUG_MIN_ALLOC_LEN, fmt, ap2); + va_end(ap2); if (len <= UDEBUG_MIN_ALLOC_LEN) goto out; |