diff options
author | Jouni Malinen <jouni.malinen@atheros.com> | 2011-04-14 20:22:21 +0300 |
---|---|---|
committer | Jouni Malinen <j@w1.fi> | 2011-04-14 20:22:21 +0300 |
commit | fe655a8402a51d03da2fe39da15c9bb3f845be34 (patch) | |
tree | 2bfb91de7d24df0097bb506dd01e7e14b2fb8633 /src/utils/os_unix.c | |
parent | 4a26df71078cc0587a34cdd1c2b71f09a873e7b1 (diff) | |
download | external_wpa_supplicant_8_ti-fe655a8402a51d03da2fe39da15c9bb3f845be34.zip external_wpa_supplicant_8_ti-fe655a8402a51d03da2fe39da15c9bb3f845be34.tar.gz external_wpa_supplicant_8_ti-fe655a8402a51d03da2fe39da15c9bb3f845be34.tar.bz2 |
Add sanity checks for fseek and ftell return values
In theory, these calls could fail, but it is not really likely to
happen in practice in the use case here. Anyway, check that they do
not return an error before accepting the length of the file.
Diffstat (limited to 'src/utils/os_unix.c')
-rw-r--r-- | src/utils/os_unix.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c index 9a2465a..4e11758 100644 --- a/src/utils/os_unix.c +++ b/src/utils/os_unix.c @@ -315,14 +315,21 @@ char * os_readfile(const char *name, size_t *len) { FILE *f; char *buf; + long pos; f = fopen(name, "rb"); if (f == NULL) return NULL; - fseek(f, 0, SEEK_END); - *len = ftell(f); - fseek(f, 0, SEEK_SET); + if (fseek(f, 0, SEEK_END) < 0 || (pos = ftell(f)) < 0) { + fclose(f); + return NULL; + } + *len = pos; + if (fseek(f, 0, SEEK_SET) < 0) { + fclose(f); + return NULL; + } buf = os_malloc(*len); if (buf == NULL) { |