fix: add missing error checks for chdir
This commit is contained in:
parent
1219501aaa
commit
865141177a
@ -145,6 +145,9 @@ typedef enum lm_error {
|
||||
LM_ERR_FileNotExist = 143,
|
||||
LM_ERR_FileNotLink = 144,
|
||||
LM_ERR_ArchiveSetFail = 145,
|
||||
LM_ERR_ChdirFail = 146,
|
||||
LM_ERR_ExtractRootChdirFail = 147,
|
||||
LM_ERR_ExtractOldChdirFail = 148,
|
||||
} lm_error_t;
|
||||
|
||||
typedef struct lm_error_desc {
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-08-06 04:34+0300\n"
|
||||
"POT-Creation-Date: 2024-08-07 01:28+0300\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -617,3 +617,16 @@ msgstr ""
|
||||
#: src/error.c:164
|
||||
msgid "failed to set the package archive"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:165
|
||||
#, c-format
|
||||
msgid "failed change directory: %s"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:166
|
||||
msgid "failed to change directory to root during extraction"
|
||||
msgstr ""
|
||||
|
||||
#: src/error.c:167
|
||||
msgid "failed to change directory back from root during extraction"
|
||||
msgstr ""
|
||||
|
@ -107,7 +107,10 @@ bool __lm_ctx_extract_files(lm_ctx_t *ctx, lm_pkg_t *pkg, char *files, lm_ctx_in
|
||||
goto end;
|
||||
}
|
||||
|
||||
chdir(ctx->root);
|
||||
if(chdir(ctx->root) < 0){
|
||||
lm_error_set(LM_ERR_ExtractRootChdirFail);
|
||||
goto end;
|
||||
}
|
||||
|
||||
flags = ARCHIVE_EXTRACT_PERM;
|
||||
flags |= ARCHIVE_EXTRACT_UNLINK;
|
||||
@ -202,7 +205,10 @@ end:
|
||||
}
|
||||
|
||||
if (NULL != oldpwd) {
|
||||
chdir(oldpwd);
|
||||
if(chdir(oldpwd) < 0){
|
||||
lm_error_set(LM_ERR_ExtractOldChdirFail);
|
||||
ret = false;
|
||||
}
|
||||
free(oldpwd);
|
||||
}
|
||||
|
||||
|
@ -162,6 +162,9 @@ void lm_error_set(lm_error_t code, ...) {
|
||||
{.code = LM_ERR_FileNotExist, .desc = _("file does not exist: %s") },
|
||||
{.code = LM_ERR_FileNotLink, .desc = _("file is a symbolic link: %s") },
|
||||
{.code = LM_ERR_ArchiveSetFail, .desc = _("failed to set the package archive") },
|
||||
{.code = LM_ERR_ChdirFail, .desc = _("failed change directory: %s") },
|
||||
{.code = LM_ERR_ExtractRootChdirFail, .desc = _("failed to change directory to root during extraction") },
|
||||
{.code = LM_ERR_ExtractOldChdirFail, .desc = _("failed to change directory back from root during extraction")},
|
||||
};
|
||||
|
||||
char *fmt = NULL;
|
||||
|
10
src/util.c
10
src/util.c
@ -154,7 +154,10 @@ bool extract_archive(char *dst, char *src) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
chdir(dst);
|
||||
if (chdir(dst) < 0) {
|
||||
lm_error_set(LM_ERR_ChdirFail, dst);
|
||||
goto end;
|
||||
}
|
||||
|
||||
flags = ARCHIVE_EXTRACT_PERM;
|
||||
flags |= ARCHIVE_EXTRACT_UNLINK;
|
||||
@ -214,7 +217,10 @@ end:
|
||||
}
|
||||
|
||||
if (NULL != oldpwd) {
|
||||
chdir(oldpwd);
|
||||
if (chdir(oldpwd) < 0) {
|
||||
lm_error_set(LM_ERR_ChdirFail, oldpwd);
|
||||
ret = false;
|
||||
}
|
||||
free(oldpwd);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user