Skip to content

Commit c1be505

Browse files
committed
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 <[email protected]>
1 parent 6339204 commit c1be505

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

udebug.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ int udebug_entry_vprintf(struct udebug_buf *buf, const char *fmt, va_list ap)
610610
struct udebug_ptr *ptr;
611611
uint32_t ofs;
612612
uint32_t len;
613+
va_list ap2;
613614
char *str;
614615

615616
if (!hdr)
@@ -621,7 +622,9 @@ int udebug_entry_vprintf(struct udebug_buf *buf, const char *fmt, va_list ap)
621622
return -1;
622623

623624
str = udebug_buf_alloc(buf, ofs, UDEBUG_MIN_ALLOC_LEN);
624-
len = vsnprintf(str, UDEBUG_MIN_ALLOC_LEN, fmt, ap);
625+
va_copy(ap2, ap);
626+
len = vsnprintf(str, UDEBUG_MIN_ALLOC_LEN, fmt, ap2);
627+
va_end(ap2);
625628
if (len <= UDEBUG_MIN_ALLOC_LEN)
626629
goto out;
627630

0 commit comments

Comments
 (0)