Applying Michael Samuel's patch to avoid buffer overflow while loading

the algorithm name from a dump file.
This commit is contained in:
Fabiano C. Botelho 2013-04-15 23:42:21 -07:00
parent b8c5b54c9a
commit f9e5adacbd

View File

@ -38,13 +38,18 @@ cmph_t *__cmph_load(FILE *f)
register size_t nbytes; register size_t nbytes;
DEBUGP("Loading mphf\n"); DEBUGP("Loading mphf\n");
while(1) for(i = 0; i < BUFSIZ; i++)
{ {
size_t c = fread(ptr, (size_t)1, (size_t)1, f); size_t c = fread(ptr, (size_t)1, (size_t)1, f);
if (c != 1) return NULL; if (c != 1) return NULL;
if (*ptr == 0) break; if (*ptr == 0) break;
++ptr; ++ptr;
} }
if(algo_name[i] != 0)
{
DEBUGP("Attempted buffer overflow while loading mph file\n");
return NULL;
}
for(i = 0; i < CMPH_COUNT; ++i) for(i = 0; i < CMPH_COUNT; ++i)
{ {
if (strcmp(algo_name, cmph_names[i]) == 0) if (strcmp(algo_name, cmph_names[i]) == 0)