Skip to content

Commit

Permalink
udebug: fix crash in udebug_entry_vprintf with longer strings
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
nbd168 committed Jan 26, 2024
1 parent 6339204 commit c1be505
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion udebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;

Expand Down

0 comments on commit c1be505

Please sign in to comment.