FS-6429: --resolve check return values of fread and gets

This commit is contained in:
Michael Jerris 2014-04-03 21:43:12 -04:00
parent 98237f5962
commit 5320075df7
1 changed files with 17 additions and 7 deletions

View File

@ -3646,11 +3646,14 @@ int mb_load_file(mb_interpreter_t* s, const char* f) {
fseek(fp, curpos, SEEK_SET); fseek(fp, curpos, SEEK_SET);
buf = (char*)mb_malloc((size_t)(l + 1)); buf = (char*)mb_malloc((size_t)(l + 1));
mb_assert(buf); mb_assert(buf);
fread(buf, 1, l, fp); if(fread(buf, 1, l, fp) == l ) {
fclose(fp);
buf[l] = '\0'; buf[l] = '\0';
result = mb_load_string(s, buf); result = mb_load_string(s, buf);
} else {
_set_current_error(s, SE_PS_FILE_OPEN_FAILED);
++result;
}
fclose(fp);
mb_free(buf); mb_free(buf);
if(result) { if(result) {
goto _exit; goto _exit;
@ -5637,7 +5640,10 @@ int _std_input(mb_interpreter_t* s, void** l) {
obj = (_object_t*)(ast->data); obj = (_object_t*)(ast->data);
if(obj->data.variable->data->type == _DT_INT || obj->data.variable->data->type == _DT_REAL) { if(obj->data.variable->data->type == _DT_INT || obj->data.variable->data->type == _DT_REAL) {
gets(line); if(!gets(line)) {
result = MB_FUNC_ERR;
goto _exit;
}
obj->data.variable->data->type = _DT_INT; obj->data.variable->data->type = _DT_INT;
obj->data.variable->data->data.integer = (int_t)strtol(line, &conv_suc, 0); obj->data.variable->data->data.integer = (int_t)strtol(line, &conv_suc, 0);
if(*conv_suc != '\0') { if(*conv_suc != '\0') {
@ -5654,12 +5660,16 @@ int _std_input(mb_interpreter_t* s, void** l) {
} }
obj->data.variable->data->data.string = (char*)mb_malloc(256); obj->data.variable->data->data.string = (char*)mb_malloc(256);
memset(obj->data.variable->data->data.string, 0, 256); memset(obj->data.variable->data->data.string, 0, 256);
gets(line); if(gets(line)) {
strcpy(obj->data.variable->data->data.string, line); strcpy(obj->data.variable->data->data.string, line);
} else { } else {
result = MB_FUNC_ERR; result = MB_FUNC_ERR;
goto _exit; goto _exit;
} }
} else {
result = MB_FUNC_ERR;
goto _exit;
}
_exit: _exit:
*l = ast; *l = ast;