diff options
author | Yunchih Chen <yunchih.cat@gmail.com> | 2018-03-20 18:06:48 +0800 |
---|---|---|
committer | Yunchih Chen <yunchih.cat@gmail.com> | 2018-03-20 18:16:33 +0800 |
commit | b4dad31a95ebb45a44a719b1c190e445ae5b5afb (patch) | |
tree | da58fda61d37eb5b1949417f53c14657d7ea5d3e | |
parent | a1ebe8daa40c49621fd33b0c34d99227a0be9295 (diff) | |
download | nfcollect-b4dad31a95ebb45a44a719b1c190e445ae5b5afb.tar.gz nfcollect-b4dad31a95ebb45a44a719b1c190e445ae5b5afb.tar.zst nfcollect-b4dad31a95ebb45a44a719b1c190e445ae5b5afb.zip |
Check chdir, getcwd, fread return errors
-rw-r--r-- | bin/nfcollect.c | 6 | ||||
-rw-r--r-- | lib/extract.c | 4 |
2 files changed, 5 insertions, 5 deletions
diff --git a/bin/nfcollect.c b/bin/nfcollect.c index 2c88ad1..4168fd7 100644 --- a/bin/nfcollect.c +++ b/bin/nfcollect.c @@ -197,8 +197,8 @@ static uint32_t calculate_starting_trunk(const char *storage_dir) { ERR(!(dp = opendir(storage_dir)), "Can't open the storage directory"); - getcwd(cwd, sizeof(cwd)); - chdir(storage_dir); + ERR(!getcwd(cwd, sizeof(cwd)), "getcwd"); + ERR(chdir(storage_dir) < 0, "chdir"); while ((ep = readdir(dp))) { const char *fn = ep->d_name; @@ -213,6 +213,6 @@ static uint32_t calculate_starting_trunk(const char *storage_dir) { } closedir(dp); - chdir(cwd); + ERR(chdir(cwd) < 0, "chdir"); return newest_index; } diff --git a/lib/extract.c b/lib/extract.c index 11381d7..21d51d0 100644 --- a/lib/extract.c +++ b/lib/extract.c @@ -44,8 +44,8 @@ static int nfl_extract_zstd(FILE *f, nfl_state_t *state) { // It's possible that data or header is not written due to broken commit WARN_RETURN(compressed_size <= 0, "%s", "zstd: no data in this trunk"); - ERR(!(buf = malloc(compressed_size)), "zstd: cannot malloc"); - fread(buf, compressed_size, 1, f); + WARN_RETURN(!(buf = malloc(compressed_size)), "zstd: cannot malloc"); + WARN_RETURN(!fread(buf, compressed_size, 1, f), "zstd: broken data section"); WARN_RETURN(ferror(f), "%s", strerror(errno)); size_t const estimate_decom_size = |