Skip to content

Commit

Permalink
Check strfmt length, make sure it never overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
JiapengLi committed Sep 3, 2016
1 parent 6317d61 commit 370f14c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <unistd.h>
#include "log.h"

#define LOG_STRFMT_LEN (10)

#if defined _WIN32 || defined __CYGWIN__
#ifndef WIN32
#define WIN32
Expand Down Expand Up @@ -44,7 +46,7 @@ int log_puts(int priority, char *fmt, ...)
char c, *s;
uint8_t *hbuf;
double f;
char strfmt[10];
char strfmt[LOG_STRFMT_LEN+2];
va_list ap;

#ifndef WIN32
Expand Down Expand Up @@ -131,6 +133,9 @@ int log_puts(int priority, char *fmt, ...)
( fmt[j]== '-' ) || ( fmt[j]== '+' ) || ( fmt[j]== '.' ) ){
strfmt[j] = fmt[j];
j++;
if(j == LOG_STRFMT_LEN){
break;
}
}
strfmt[j] = fmt[j];
fmt += j;
Expand Down

0 comments on commit 370f14c

Please sign in to comment.