1
0
mirror of https://github.com/benhoyt/inih.git synced 2025-02-05 07:08:23 +08:00

Fix possible int overflow in reader cb (#88)

This commit is contained in:
Anatol Belski 2019-10-08 19:54:08 +02:00 committed by Ben Hoyt
parent 6edb31a218
commit 0a87bf1669

8
ini.c
View File

@ -89,11 +89,11 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
int max_line = INI_MAX_LINE;
#else
char* line;
int max_line = INI_INITIAL_ALLOC;
size_t max_line = INI_INITIAL_ALLOC;
#endif
#if INI_ALLOW_REALLOC && !INI_USE_STACK
char* new_line;
int offset;
size_t offset;
#endif
char section[MAX_SECTION] = "";
char prev_name[MAX_NAME] = "";
@ -119,7 +119,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
#endif
/* Scan through stream line by line */
while (reader(line, max_line, stream) != NULL) {
while (reader(line, (int)max_line, stream) != NULL) {
#if INI_ALLOW_REALLOC && !INI_USE_STACK
offset = strlen(line);
while (offset == max_line - 1 && line[offset - 1] != '\n') {
@ -132,7 +132,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
return -2;
}
line = new_line;
if (reader(line + offset, max_line - offset, stream) == NULL)
if (reader(line + offset, (int)(max_line - offset), stream) == NULL)
break;
if (max_line >= INI_MAX_LINE)
break;