fix dynamic-stack-buffer-overflow

This commit is contained in:
Ray Lee 2021-08-24 22:36:59 +08:00
parent 1cdddc270f
commit 8998b0b46c

View file

@ -11,6 +11,7 @@
#include "ndef.h" #include "ndef.h"
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "ui.h" #include "ui.h"
#include "util.h" // sprint_hex... #include "util.h" // sprint_hex...
@ -637,7 +638,7 @@ static int ndefDecodePayload(NDEFHeader_t *ndef) {
break; break;
} }
char begin[ndef->TypeLen]; char *begin = calloc(ndef->TypeLen + 1,sizeof(char));
memcpy(begin, ndef->Type, ndef->TypeLen); memcpy(begin, ndef->Type, ndef->TypeLen);
str_lower(begin); str_lower(begin);
@ -651,6 +652,8 @@ static int ndefDecodePayload(NDEFHeader_t *ndef) {
ndefDecodeMime_bt(ndef); ndefDecodeMime_bt(ndef);
} }
free(begin);
begin = NULL;
break; break;
} }
case tnfAbsoluteURIRecord: case tnfAbsoluteURIRecord: