X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=builtins%2Fevalfile.c;h=bb3217d3bf128c2b5e9e2cea646d8faa76a76f50;hb=cce855bc5b117cb7ae70064131120687bc69fac0;hp=3ffccbe4932010980610398b626a737e1a66dbc5;hpb=e8ce775db824de329b81293b4e5d8fbd65624528;p=platform%2Fupstream%2Fbash.git diff --git a/builtins/evalfile.c b/builtins/evalfile.c index 3ffccbe..bb3217d 100644 --- a/builtins/evalfile.c +++ b/builtins/evalfile.c @@ -75,6 +75,7 @@ _evalfile (filename, flags) int return_val, fd, result, pflags; char *string; struct stat finfo; + size_t file_size; VFunction *errfunc; fd = open (filename, O_RDONLY); @@ -108,20 +109,33 @@ file_error_and_exit: return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1); } - string = xmalloc (1 + (int)finfo.st_size); - result = read (fd, string, finfo.st_size); + file_size = (size_t)finfo.st_size; + /* Check for overflow with large files. */ + if (file_size != finfo.st_size || file_size + 1 < file_size) + { + (*errfunc) ("%s: file is too large", filename); + return ((flags & FEVAL_BUILTIN) ? EXECUTION_FAILURE : -1); + } + string = xmalloc (1 + file_size); + result = read (fd, string, file_size); string[result] = '\0'; return_val = errno; close (fd); errno = return_val; - if (result != (int)finfo.st_size) + if (result < 0) /* XXX was != file_size, not < 0 */ { free (string); goto file_error_and_exit; } + if (result == 0) + { + free (string); + return ((flags & FEVAL_BUILTIN) ? EXECUTION_SUCCESS : 1); + } + if (check_binary_file ((unsigned char *)string, (result > 80) ? 80 : result)) { free (string);