Skip to content

Commit

Permalink
string_format: fix nasty off-by-one bug that causes stack corruption.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Slagter committed Mar 13, 2016
1 parent f7b372c commit 6507ff8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion util.c
Expand Up @@ -83,8 +83,13 @@ irom void string_format_ptr(string_t *dst, const char *fmt_flash, ...)
copy_flash_to_ram(dram_buffer, fmt_flash, sizeof(dram_buffer));

va_start(ap, fmt_flash);
dst->length += ets_vsnprintf(dst->buffer + dst->length, dst->size - dst->length, dram_buffer, ap);
dst->length += ets_vsnprintf(dst->buffer + dst->length, dst->size - dst->length - 1, dram_buffer, ap);
va_end(ap);

if(dst->length > (dst->size - 1))
dst->length = dst->size - 1;

dst->buffer[dst->length] = '\0';
}

irom void string_cat_strptr(string_t *dst, const char *src)
Expand Down

0 comments on commit 6507ff8

Please sign in to comment.