Fix potential integer overflow in allocStr

This commit is contained in:
Tatsuya Kinoshita
2021-03-27 20:04:56 +09:00
parent 16b3875745
commit d0a30912c8

View File

@@ -104,6 +104,8 @@ allocStr(const char *s, int len)
return NULL;
if (len < 0)
len = strlen(s);
if (len < 0 || len >= STR_SIZE_MAX)
len = STR_SIZE_MAX - 1;
ptr = NewAtom_N(char, len + 1);
if (ptr == NULL) {
fprintf(stderr, "fm: Can't allocate string. Give me more memory!\n");