libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit b7ec52dcd7c18f4eeb44b6e978d2c8b452722aca
parent 9370cd5663399d86029af8c4ed83d6d3b4ee7fb2
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue,  4 Jul 2017 18:01:06 +0200

Fix(packer_extract_archive): Forgot to check the return of a syscall

Diffstat:
Msrc/packer.c | 9++++++++-
Mtests/test_packer.c | 6++++++
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/packer.c b/src/packer.c @@ -1066,7 +1066,14 @@ bool packer_extract_archive(packer_t *ctx, const char *dir) { /* If it's non-existent, create it */ if (p_dir == NULL) - mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO); + { + if (mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO) == -1) + { + SET_ERR(ERR_MKDIR_FAILED); + SET_ERR_STR_FMT("Cannot create directory '%s'\n", dir); + goto cleanup; + } + } else closedir(p_dir); diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -605,6 +605,12 @@ TEST(packer_extract_archive_2) { ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_mkdir_fail(0); + TEST_ASSERT(packer_extract_archive(ctx, "/tmp/some_non_existent_dir") == false, "Error did not raise"); + packer_free(ctx); + recursive_delete("/tmp/some_non_existent_dir"); + + ctx = packer_init_archive(PACKAGE_OUTPUT_FN); + set_mkdir_fail(0); TEST_ASSERT(packer_extract_archive(ctx, "/tmp/") == false, "Error did not raise"); packer_free(ctx); recursive_delete("/tmp/test-2.0");