Changeset 33009


Ignore:
Timestamp:
Aug 3, 2017, 11:35:21 PM (3 weeks ago)
Author:
brainslayer
Message:

cannot use allocated memory here, i have seen corrupted memory caused by vasprintf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/router/libutils/airbag.c

    r33008 r33009  
    411411{
    412412        static char *ss_buffer = NULL;
    413         static int clear=0;
    414         char *temp;
     413        static char temp[128];;
    415414        va_list args;
    416415        va_start(args, fmt);
    417         int size = vasprintf(&temp, fmt, args);
     416        int size = vsnprintf(temp, 128, fmt, args);
    418417        va_end(args);
    419418
    420419        if (!size || size < 0)
    421420                return 0;
    422         if (!clear) {
     421        if (!ss_buffer) {
    423422                ss_buffer = strdup(temp);
    424                 clear = 1;
    425423        } else {
    426424                ss_buffer = realloc(ss_buffer, strlen(ss_buffer) + strlen(temp) + 1);
    427425                strcat(ss_buffer, temp);
    428426        }
    429         free(temp);
    430427        if (strchr(ss_buffer, '\n')) {
    431428                slog(LOG_ERR, ss_buffer);
    432429                fprintf(stderr, "%s", ss_buffer);
    433430                free(ss_buffer);
    434                 clear=0;
     431                ss_buffer = NULL;
    435432        }
    436433        return size;
Note: See TracChangeset for help on using the changeset viewer.