From 865141177a7c5b2b80c91657893a08df94ac3cc4 Mon Sep 17 00:00:00 2001 From: ngn Date: Wed, 7 Aug 2024 01:29:09 +0300 Subject: [PATCH] fix: add missing error checks for chdir --- include/error.h | 3 + locale/tr/LC_MESSAGES/libmp.po | 15 +- src/ctx/install.c | 10 +- src/error.c | 293 +++++++++++++++++---------------- src/util.c | 10 +- 5 files changed, 181 insertions(+), 150 deletions(-) diff --git a/include/error.h b/include/error.h index 72363b1..016866d 100644 --- a/include/error.h +++ b/include/error.h @@ -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 { diff --git a/locale/tr/LC_MESSAGES/libmp.po b/locale/tr/LC_MESSAGES/libmp.po index 280f7dd..c3a2b56 100644 --- a/locale/tr/LC_MESSAGES/libmp.po +++ b/locale/tr/LC_MESSAGES/libmp.po @@ -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 \n" "Language-Team: LANGUAGE \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 "" diff --git a/src/ctx/install.c b/src/ctx/install.c index 6060565..a312e61 100644 --- a/src/ctx/install.c +++ b/src/ctx/install.c @@ -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); } diff --git a/src/error.c b/src/error.c index f6a526b..a1fc9ad 100644 --- a/src/error.c +++ b/src/error.c @@ -16,152 +16,155 @@ void lm_error_clear() { void lm_error_set(lm_error_t code, ...) { lm_error_desc_t errors[] = { - {.code = LM_ERR_NoError, .desc = _("no error") }, - {.code = LM_ERR_URLBadChar, .desc = _("URL contains an invalid character") }, - {.code = LM_ERR_URLBadProtocol, .desc = _("URL does not have a valid protocol field") }, - {.code = LM_ERR_URLTooLarge, .desc = _("URL is too large") }, - {.code = LM_ERR_URLHostLarge, .desc = _("URL hostname is too large") }, - {.code = LM_ERR_URLPathLarge, .desc = _("URL path is too large") }, - {.code = LM_ERR_URLBadHost, .desc = _("URL does not have a valid hostname") }, - {.code = LM_ERR_URLBadPort, .desc = _("URL does not have a valid port number") }, - {.code = LM_ERR_URLBadPath, .desc = _("URL does not have a valid path") }, - {.code = LM_ERR_BadPort, .desc = _("hostname does not contain a valid port number") }, - {.code = LM_ERR_BadHost, .desc = _("hostname is not valid") }, - {.code = LM_ERR_URLPortUnknown, .desc = _("URL protocol port number is unknown") }, - {.code = LM_ERR_URLEnd, .desc = _("URL is incomplete") }, - {.code = LM_ERR_PoolNoSupport, .desc = _("pool does not support the specified protocol") }, - {.code = LM_ERR_MPTPBadVersion, .desc = _("unsupported MPTP version") }, - {.code = LM_ERR_MPTPBadCode, .desc = _("invalid MPTP request/response code") }, - {.code = LM_ERR_MPTPBadUrl, .desc = _("invalid MPTP URL") }, - {.code = LM_ERR_MPTPHostFail, .desc = _("failed to resolve hostname for MPTP connection") }, - {.code = LM_ERR_MPTPSocketFail, .desc = _("failed to create a MPTP socket") }, - {.code = LM_ERR_MPTPConnectFail, .desc = _("failed to connect to the MPTP host") }, - {.code = LM_ERR_MPTPRecvFail, .desc = _("failed receive MPTP data from host") }, - {.code = LM_ERR_MPTPSendFail, .desc = _("failed send MPTP data to host") }, - {.code = LM_ERR_MPTPBadData, .desc = _("MPTP data size is invalid") }, - {.code = LM_ERR_MPTPBadHost, .desc = _("MPTP host size is invalid") }, - {.code = LM_ERR_MPTPSetsockopt, .desc = _("failed to set MPTP socket options") }, - {.code = LM_ERR_MPTPTimeout, .desc = _("MPTP connection timed out") }, - {.code = LM_ERR_MPTPBindFail, .desc = _("failed to bind MPTP socket") }, - {.code = LM_ERR_ArgNULL, .desc = _("required argument is a NULL pointer or 0") }, - {.code = LM_ERR_MPTPNotRequest, .desc = _("not a MPTP request") }, - {.code = LM_ERR_MPTPNotResponse, .desc = _("not a MPTP response") }, - {.code = LM_ERR_MPTPNotLast, .desc = _("MPTP request last flag is not set") }, - {.code = LM_ERR_MPTPNotLast, .desc = _("MPTP request last flag is not set") }, - {.code = LM_ERR_NoPort, .desc = _("host port not specified") }, - {.code = LM_ERR_PoolInfoBad, .desc = _("pool info is badly formatted or is not complete") }, - {.code = LM_ERR_ArcWBlockFail, .desc = _("failed to write block from archive") }, - {.code = LM_ERR_ArcRBlockFail, .desc = _("failed to read block from archive") }, - {.code = LM_ERR_ArcOpenFail, .desc = _("failed to open archive") }, - {.code = LM_ERR_ArcWHeaderFail, .desc = _("failed to write archive header") }, - {.code = LM_ERR_ArcWEntryFail, .desc = _("failed to finish writing the archive entry") }, - {.code = LM_ERR_ArcNewFail, .desc = _("failed to create new archive reader/writer") }, - {.code = LM_ERR_ArcRealpathFail, .desc = _("failed to resolve full path for archive file") }, - {.code = LM_ERR_ArcNextHeaderFail, .desc = _("failed to read the next header of the archive") }, - {.code = LM_ERR_GetCwdFail, .desc = _("failed to obtain current working directory") }, - {.code = LM_ERR_PoolListDirFail, .desc = _("failed to open extracted pool list directory") }, - {.code = LM_ERR_PoolListCantRead, .desc = _("failed to read access the pool list file") }, - {.code = LM_ERR_PoolInfoCantRead, .desc = _("failed to read access the pool info file") }, - {.code = LM_ERR_PkgDataBad, .desc = _("failed to parse package data") }, - {.code = LM_ERR_PkgBadName, .desc = _("package name is invalid") }, - {.code = LM_ERR_CtxDataNULL, .desc = _("data path is not set with in the ctx") }, - {.code = LM_ERR_CtxTempNULL, .desc = _("temp path is not set with in the ctx") }, - {.code = LM_ERR_CtxRootNULL, .desc = _("root path is not set with in the ctx") }, - {.code = LM_ERR_CtxTempFail, .desc = _("failed to set the ctx temp director to %s: %s") }, - {.code = LM_ERR_CtxRootFail, .desc = _("failed to set the ctx root directory to %s: %s") }, - {.code = LM_ERR_CtxDataFail, .desc = _("failed to set the ctx data directory to %s: %s") }, - {.code = LM_ERR_PoolTestNotPong, .desc = _("pool did not respond ping with pong") }, - {.code = LM_ERR_PkgPathsEmpty, .desc = _("package file and directory paths are empty") }, - {.code = LM_ERR_SendOpenFail, .desc = _("failed to to open target file for sending") }, - {.code = LM_ERR_RecvDelFail, .desc = _("failed to to delete target file for receiving") }, - {.code = LM_ERR_RecvOpenFail, .desc = _("failed to to open target file for receiving") }, - {.code = LM_ERR_RecvBadCode, .desc = _("got a bad response code for receiving the target file") }, - {.code = LM_ERR_RecvWriteFail, .desc = _("failed to write to the target file for receiving") }, - {.code = LM_ERR_PkgNotFound, .desc = _("package not found") }, - {.code = LM_ERR_DbCantAccess, .desc = _("failed to access to the database file/directory") }, - {.code = LM_ERR_DbSqlOpenFail, .desc = _("failed to open SQLite database") }, - {.code = LM_ERR_DbSqlCreateFail, .desc = _("failed to create table in SQLite database") }, - {.code = LM_ERR_DbSqlPrepareFail, .desc = _("failed to prepare statement for SQLite database") }, - {.code = LM_ERR_DbSqlInsertFail, .desc = _("failed to insert to the table in SQLite database") }, - {.code = LM_ERR_DbSqlSelectFail, .desc = _("failed to select from the table in SQLite database") }, - {.code = LM_ERR_DbSqlDeleteFail, .desc = _("failed to delete from the table in SQLite database") }, - {.code = LM_ERR_DbSqlNotFound, .desc = _("failed to find entry in SQLite database") }, - {.code = LM_ERR_PkgGPGFail, .desc = _("failed to init GPG for package verification") }, - {.code = LM_ERR_PkgGPGSigFail, .desc = _("failed to import signature to GPG for package verification")}, - {.code = LM_ERR_PkgGPGArchiveFail, .desc = _("failed to import archive to GPG for package verification") }, - {.code = LM_ERR_PkgSigNoMatch, .desc = _("package signature verification failed with zero matches") }, - {.code = LM_ERR_PkgSigNoResult, .desc = _("package signature verification failed with zero results") }, - {.code = LM_ERR_PoolPathsEmpty, .desc = _("pool file and directory paths are empty") }, - {.code = LM_ERR_PoolNotAvailable, .desc = _("pool is not avaliable for connection") }, - {.code = LM_ERR_PoolUrlEmpty, .desc = _("pool URL is empty or invalid") }, - {.code = LM_ERR_PoolBadDir, .desc = _("pool directory path is not accessible") }, - {.code = LM_ERR_PoolBadPaths, .desc = _("pool directory sub-paths are not accessible") }, - {.code = LM_ERR_DbFilesNotFound, .desc = _("package file list not found in the database") }, - {.code = LM_ERR_DbFilesOpenFail, .desc = _("failed to open package file list in the database") }, - {.code = LM_ERR_DbFilesDirFail, .desc = _("failed to access package file list database directory") }, - {.code = LM_ERR_DbFilesUnlinkFail, .desc = _("failed to remove package file list from the database") }, - {.code = LM_ERR_DbFilesWriteFail, .desc = _("failed to write to the file list in the database") }, - {.code = LM_ERR_DbKeepsNotFound, .desc = _("package keep list not found in the database") }, - {.code = LM_ERR_DbKeepsOpenFail, .desc = _("failed to open package keep list in the database") }, - {.code = LM_ERR_DbKeepsDirFail, .desc = _("failed to access package keep list database directory") }, - {.code = LM_ERR_DbKeepsUnlinkFail, .desc = _("failed to remove package keep list from the database") }, - {.code = LM_ERR_DependNotFound, .desc = _("failed to find %s (dependency of %s)") }, - {.code = LM_ERR_InstallDownloadFail, .desc = _("failed to download %s for installation: %s") }, - {.code = LM_ERR_PkgNotDownloaded, .desc = _("package is not downloaded") }, - {.code = LM_ERR_PkgRemoveDownloadFail, .desc = _("failed to remove downloaded package") }, - {.code = LM_ERR_PkgRemoveDownloadFail, .desc = _("failed to remove downloaded package") }, - {.code = LM_ERR_DstOpenFail, .desc = _("failed to open the destination file") }, - {.code = LM_ERR_SrcOpenFail, .desc = _("failed to open the source file") }, - {.code = LM_ERR_DstWriteFail, .desc = _("failed to write to the destination file") }, - {.code = LM_ERR_DstWriteFail, .desc = _("failed to write to the destination file") }, - {.code = LM_ERR_PkgNoPool, .desc = _("package does not have associated pool") }, - {.code = LM_ERR_CtxTempFailMkdir, .desc = _("failed to create specified temp directory") }, - {.code = LM_ERR_PkgBadArchive, .desc = _("package archive does not contain required files") }, - {.code = LM_ERR_PkgDataNotMatch, .desc = _("package data does not match with target package") }, - {.code = LM_ERR_PkgChangesUpdateFail, .desc = _("failed to update changes file for package: %s") }, - {.code = LM_ERR_PkgHashesOpenFail, .desc = _("failed to access package hashes file") }, - {.code = LM_ERR_DbChangesUnlinkFail, .desc = _("failed to remove package changes file from the database") }, - {.code = LM_ERR_SendStatFail, .desc = _("failed to stat target file for sending") }, - {.code = LM_ERR_SendSnprintfFail, .desc = _("failed to format target file size for sending") }, - {.code = LM_ERR_SendReadFail, .desc = _("failed to read target file size for sending") }, - {.code = LM_ERR_RecvBadSize, .desc = _("failed to parse target file size for receiving") }, - {.code = LM_ERR_RecvNotCompleted, .desc = _("target file is not fully received") }, - {.code = LM_ERR_ExtractStatFail, .desc = _("failed to stat for target extract archive") }, - {.code = LM_ERR_PkgFilesAddFail, .desc = _("failed to add package file (%s) to the database: %s") }, - {.code = LM_ERR_PkgExtractFilesFail, .desc = _("failed to extract package files: %s") }, - {.code = LM_ERR_PkgDatabaseAddFail, .desc = _("failed to add package to the database: %s") }, - {.code = LM_ERR_PkgAlreadyInstalled, .desc = _("package is already installed") }, - {.code = LM_ERR_PkgNotInstalled, .desc = _("package is not installed") }, - {.code = LM_ERR_PkgFileUnlinkFail, .desc = _("failed to remove package file (%s): %s") }, - {.code = LM_ERR_PkgDatabaseDelFail, .desc = _("failed to remove package from the database: %s") }, - {.code = LM_ERR_PkgFilesDelFail, .desc = _("failed to remove package files from the database: %s") }, - {.code = LM_ERR_PkgChangesDelFail, .desc = _("failed to remove changes file for package: %s") }, - {.code = LM_ERR_InstallCwdFail, .desc = _("failed to get current directory for running install") }, - {.code = LM_ERR_InstallRootChdirFail, .desc = _("failed change directory to root for running install") }, - {.code = LM_ERR_InstallSpawnFail, .desc = _("failed run install spawn command") }, + {.code = LM_ERR_NoError, .desc = _("no error") }, + {.code = LM_ERR_URLBadChar, .desc = _("URL contains an invalid character") }, + {.code = LM_ERR_URLBadProtocol, .desc = _("URL does not have a valid protocol field") }, + {.code = LM_ERR_URLTooLarge, .desc = _("URL is too large") }, + {.code = LM_ERR_URLHostLarge, .desc = _("URL hostname is too large") }, + {.code = LM_ERR_URLPathLarge, .desc = _("URL path is too large") }, + {.code = LM_ERR_URLBadHost, .desc = _("URL does not have a valid hostname") }, + {.code = LM_ERR_URLBadPort, .desc = _("URL does not have a valid port number") }, + {.code = LM_ERR_URLBadPath, .desc = _("URL does not have a valid path") }, + {.code = LM_ERR_BadPort, .desc = _("hostname does not contain a valid port number") }, + {.code = LM_ERR_BadHost, .desc = _("hostname is not valid") }, + {.code = LM_ERR_URLPortUnknown, .desc = _("URL protocol port number is unknown") }, + {.code = LM_ERR_URLEnd, .desc = _("URL is incomplete") }, + {.code = LM_ERR_PoolNoSupport, .desc = _("pool does not support the specified protocol") }, + {.code = LM_ERR_MPTPBadVersion, .desc = _("unsupported MPTP version") }, + {.code = LM_ERR_MPTPBadCode, .desc = _("invalid MPTP request/response code") }, + {.code = LM_ERR_MPTPBadUrl, .desc = _("invalid MPTP URL") }, + {.code = LM_ERR_MPTPHostFail, .desc = _("failed to resolve hostname for MPTP connection") }, + {.code = LM_ERR_MPTPSocketFail, .desc = _("failed to create a MPTP socket") }, + {.code = LM_ERR_MPTPConnectFail, .desc = _("failed to connect to the MPTP host") }, + {.code = LM_ERR_MPTPRecvFail, .desc = _("failed receive MPTP data from host") }, + {.code = LM_ERR_MPTPSendFail, .desc = _("failed send MPTP data to host") }, + {.code = LM_ERR_MPTPBadData, .desc = _("MPTP data size is invalid") }, + {.code = LM_ERR_MPTPBadHost, .desc = _("MPTP host size is invalid") }, + {.code = LM_ERR_MPTPSetsockopt, .desc = _("failed to set MPTP socket options") }, + {.code = LM_ERR_MPTPTimeout, .desc = _("MPTP connection timed out") }, + {.code = LM_ERR_MPTPBindFail, .desc = _("failed to bind MPTP socket") }, + {.code = LM_ERR_ArgNULL, .desc = _("required argument is a NULL pointer or 0") }, + {.code = LM_ERR_MPTPNotRequest, .desc = _("not a MPTP request") }, + {.code = LM_ERR_MPTPNotResponse, .desc = _("not a MPTP response") }, + {.code = LM_ERR_MPTPNotLast, .desc = _("MPTP request last flag is not set") }, + {.code = LM_ERR_MPTPNotLast, .desc = _("MPTP request last flag is not set") }, + {.code = LM_ERR_NoPort, .desc = _("host port not specified") }, + {.code = LM_ERR_PoolInfoBad, .desc = _("pool info is badly formatted or is not complete") }, + {.code = LM_ERR_ArcWBlockFail, .desc = _("failed to write block from archive") }, + {.code = LM_ERR_ArcRBlockFail, .desc = _("failed to read block from archive") }, + {.code = LM_ERR_ArcOpenFail, .desc = _("failed to open archive") }, + {.code = LM_ERR_ArcWHeaderFail, .desc = _("failed to write archive header") }, + {.code = LM_ERR_ArcWEntryFail, .desc = _("failed to finish writing the archive entry") }, + {.code = LM_ERR_ArcNewFail, .desc = _("failed to create new archive reader/writer") }, + {.code = LM_ERR_ArcRealpathFail, .desc = _("failed to resolve full path for archive file") }, + {.code = LM_ERR_ArcNextHeaderFail, .desc = _("failed to read the next header of the archive") }, + {.code = LM_ERR_GetCwdFail, .desc = _("failed to obtain current working directory") }, + {.code = LM_ERR_PoolListDirFail, .desc = _("failed to open extracted pool list directory") }, + {.code = LM_ERR_PoolListCantRead, .desc = _("failed to read access the pool list file") }, + {.code = LM_ERR_PoolInfoCantRead, .desc = _("failed to read access the pool info file") }, + {.code = LM_ERR_PkgDataBad, .desc = _("failed to parse package data") }, + {.code = LM_ERR_PkgBadName, .desc = _("package name is invalid") }, + {.code = LM_ERR_CtxDataNULL, .desc = _("data path is not set with in the ctx") }, + {.code = LM_ERR_CtxTempNULL, .desc = _("temp path is not set with in the ctx") }, + {.code = LM_ERR_CtxRootNULL, .desc = _("root path is not set with in the ctx") }, + {.code = LM_ERR_CtxTempFail, .desc = _("failed to set the ctx temp director to %s: %s") }, + {.code = LM_ERR_CtxRootFail, .desc = _("failed to set the ctx root directory to %s: %s") }, + {.code = LM_ERR_CtxDataFail, .desc = _("failed to set the ctx data directory to %s: %s") }, + {.code = LM_ERR_PoolTestNotPong, .desc = _("pool did not respond ping with pong") }, + {.code = LM_ERR_PkgPathsEmpty, .desc = _("package file and directory paths are empty") }, + {.code = LM_ERR_SendOpenFail, .desc = _("failed to to open target file for sending") }, + {.code = LM_ERR_RecvDelFail, .desc = _("failed to to delete target file for receiving") }, + {.code = LM_ERR_RecvOpenFail, .desc = _("failed to to open target file for receiving") }, + {.code = LM_ERR_RecvBadCode, .desc = _("got a bad response code for receiving the target file") }, + {.code = LM_ERR_RecvWriteFail, .desc = _("failed to write to the target file for receiving") }, + {.code = LM_ERR_PkgNotFound, .desc = _("package not found") }, + {.code = LM_ERR_DbCantAccess, .desc = _("failed to access to the database file/directory") }, + {.code = LM_ERR_DbSqlOpenFail, .desc = _("failed to open SQLite database") }, + {.code = LM_ERR_DbSqlCreateFail, .desc = _("failed to create table in SQLite database") }, + {.code = LM_ERR_DbSqlPrepareFail, .desc = _("failed to prepare statement for SQLite database") }, + {.code = LM_ERR_DbSqlInsertFail, .desc = _("failed to insert to the table in SQLite database") }, + {.code = LM_ERR_DbSqlSelectFail, .desc = _("failed to select from the table in SQLite database") }, + {.code = LM_ERR_DbSqlDeleteFail, .desc = _("failed to delete from the table in SQLite database") }, + {.code = LM_ERR_DbSqlNotFound, .desc = _("failed to find entry in SQLite database") }, + {.code = LM_ERR_PkgGPGFail, .desc = _("failed to init GPG for package verification") }, + {.code = LM_ERR_PkgGPGSigFail, .desc = _("failed to import signature to GPG for package verification") }, + {.code = LM_ERR_PkgGPGArchiveFail, .desc = _("failed to import archive to GPG for package verification") }, + {.code = LM_ERR_PkgSigNoMatch, .desc = _("package signature verification failed with zero matches") }, + {.code = LM_ERR_PkgSigNoResult, .desc = _("package signature verification failed with zero results") }, + {.code = LM_ERR_PoolPathsEmpty, .desc = _("pool file and directory paths are empty") }, + {.code = LM_ERR_PoolNotAvailable, .desc = _("pool is not avaliable for connection") }, + {.code = LM_ERR_PoolUrlEmpty, .desc = _("pool URL is empty or invalid") }, + {.code = LM_ERR_PoolBadDir, .desc = _("pool directory path is not accessible") }, + {.code = LM_ERR_PoolBadPaths, .desc = _("pool directory sub-paths are not accessible") }, + {.code = LM_ERR_DbFilesNotFound, .desc = _("package file list not found in the database") }, + {.code = LM_ERR_DbFilesOpenFail, .desc = _("failed to open package file list in the database") }, + {.code = LM_ERR_DbFilesDirFail, .desc = _("failed to access package file list database directory") }, + {.code = LM_ERR_DbFilesUnlinkFail, .desc = _("failed to remove package file list from the database") }, + {.code = LM_ERR_DbFilesWriteFail, .desc = _("failed to write to the file list in the database") }, + {.code = LM_ERR_DbKeepsNotFound, .desc = _("package keep list not found in the database") }, + {.code = LM_ERR_DbKeepsOpenFail, .desc = _("failed to open package keep list in the database") }, + {.code = LM_ERR_DbKeepsDirFail, .desc = _("failed to access package keep list database directory") }, + {.code = LM_ERR_DbKeepsUnlinkFail, .desc = _("failed to remove package keep list from the database") }, + {.code = LM_ERR_DependNotFound, .desc = _("failed to find %s (dependency of %s)") }, + {.code = LM_ERR_InstallDownloadFail, .desc = _("failed to download %s for installation: %s") }, + {.code = LM_ERR_PkgNotDownloaded, .desc = _("package is not downloaded") }, + {.code = LM_ERR_PkgRemoveDownloadFail, .desc = _("failed to remove downloaded package") }, + {.code = LM_ERR_PkgRemoveDownloadFail, .desc = _("failed to remove downloaded package") }, + {.code = LM_ERR_DstOpenFail, .desc = _("failed to open the destination file") }, + {.code = LM_ERR_SrcOpenFail, .desc = _("failed to open the source file") }, + {.code = LM_ERR_DstWriteFail, .desc = _("failed to write to the destination file") }, + {.code = LM_ERR_DstWriteFail, .desc = _("failed to write to the destination file") }, + {.code = LM_ERR_PkgNoPool, .desc = _("package does not have associated pool") }, + {.code = LM_ERR_CtxTempFailMkdir, .desc = _("failed to create specified temp directory") }, + {.code = LM_ERR_PkgBadArchive, .desc = _("package archive does not contain required files") }, + {.code = LM_ERR_PkgDataNotMatch, .desc = _("package data does not match with target package") }, + {.code = LM_ERR_PkgChangesUpdateFail, .desc = _("failed to update changes file for package: %s") }, + {.code = LM_ERR_PkgHashesOpenFail, .desc = _("failed to access package hashes file") }, + {.code = LM_ERR_DbChangesUnlinkFail, .desc = _("failed to remove package changes file from the database") }, + {.code = LM_ERR_SendStatFail, .desc = _("failed to stat target file for sending") }, + {.code = LM_ERR_SendSnprintfFail, .desc = _("failed to format target file size for sending") }, + {.code = LM_ERR_SendReadFail, .desc = _("failed to read target file size for sending") }, + {.code = LM_ERR_RecvBadSize, .desc = _("failed to parse target file size for receiving") }, + {.code = LM_ERR_RecvNotCompleted, .desc = _("target file is not fully received") }, + {.code = LM_ERR_ExtractStatFail, .desc = _("failed to stat for target extract archive") }, + {.code = LM_ERR_PkgFilesAddFail, .desc = _("failed to add package file (%s) to the database: %s") }, + {.code = LM_ERR_PkgExtractFilesFail, .desc = _("failed to extract package files: %s") }, + {.code = LM_ERR_PkgDatabaseAddFail, .desc = _("failed to add package to the database: %s") }, + {.code = LM_ERR_PkgAlreadyInstalled, .desc = _("package is already installed") }, + {.code = LM_ERR_PkgNotInstalled, .desc = _("package is not installed") }, + {.code = LM_ERR_PkgFileUnlinkFail, .desc = _("failed to remove package file (%s): %s") }, + {.code = LM_ERR_PkgDatabaseDelFail, .desc = _("failed to remove package from the database: %s") }, + {.code = LM_ERR_PkgFilesDelFail, .desc = _("failed to remove package files from the database: %s") }, + {.code = LM_ERR_PkgChangesDelFail, .desc = _("failed to remove changes file for package: %s") }, + {.code = LM_ERR_InstallCwdFail, .desc = _("failed to get current directory for running install") }, + {.code = LM_ERR_InstallRootChdirFail, .desc = _("failed change directory to root for running install") }, + {.code = LM_ERR_InstallSpawnFail, .desc = _("failed run install spawn command") }, {.code = LM_ERR_InstallBackChdirFail, - .desc = _("failed to change directory to old directory after running install") }, - {.code = LM_ERR_InstallStatusFail, .desc = _("install script returned a bad status code") }, - {.code = LM_ERR_InstallRunFail, .desc = _("failed to run the package install script: %s") }, - {.code = LM_ERR_InstallSaveFail, .desc = _("failed to save the package install script: %s") }, - {.code = LM_ERR_PkgBreaks, .desc = _("removing package breaks %s") }, - {.code = LM_ERR_PkgUpToDate, .desc = _("package is already up-to-date") }, - {.code = LM_ERR_HashOpenFail, .desc = _("failed to open file for hashing") }, - {.code = LM_ERR_HashDigestFail, .desc = _("failed create digest for hashing") }, - {.code = LM_ERR_FileHashFail, .desc = _("failed to get hash of %s: %s") }, - {.code = LM_ERR_FileHashNoMatch, .desc = _("file hash does not match for %s") }, - {.code = LM_ERR_InfoNotLoaded, .desc = _("pool info is not loaded") }, - {.code = LM_ERR_NoPools, .desc = _("pool list is empty") }, - {.code = LM_ERR_DbChangesNotExists, .desc = _("package changes file not found in the database") }, - {.code = LM_ERR_DbChangesChmodFail, .desc = _("failed to change mod of the changes file") }, - {.code = LM_ERR_InstallDirFail, .desc = _("failed to create install script save directory") }, - {.code = LM_ERR_NoWrite, .desc = _("directory does not have write permissions") }, - {.code = LM_ERR_NotDir, .desc = _("specified path is not a directory") }, - {.code = LM_ERR_FailMkdir, .desc = _("failed to create the specified directory") }, - {.code = LM_ERR_PoolListBadDir, .desc = _("specified list extraction directory is not accessible") }, - {.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") }, + .desc = _("failed to change directory to old directory after running install") }, + {.code = LM_ERR_InstallStatusFail, .desc = _("install script returned a bad status code") }, + {.code = LM_ERR_InstallRunFail, .desc = _("failed to run the package install script: %s") }, + {.code = LM_ERR_InstallSaveFail, .desc = _("failed to save the package install script: %s") }, + {.code = LM_ERR_PkgBreaks, .desc = _("removing package breaks %s") }, + {.code = LM_ERR_PkgUpToDate, .desc = _("package is already up-to-date") }, + {.code = LM_ERR_HashOpenFail, .desc = _("failed to open file for hashing") }, + {.code = LM_ERR_HashDigestFail, .desc = _("failed create digest for hashing") }, + {.code = LM_ERR_FileHashFail, .desc = _("failed to get hash of %s: %s") }, + {.code = LM_ERR_FileHashNoMatch, .desc = _("file hash does not match for %s") }, + {.code = LM_ERR_InfoNotLoaded, .desc = _("pool info is not loaded") }, + {.code = LM_ERR_NoPools, .desc = _("pool list is empty") }, + {.code = LM_ERR_DbChangesNotExists, .desc = _("package changes file not found in the database") }, + {.code = LM_ERR_DbChangesChmodFail, .desc = _("failed to change mod of the changes file") }, + {.code = LM_ERR_InstallDirFail, .desc = _("failed to create install script save directory") }, + {.code = LM_ERR_NoWrite, .desc = _("directory does not have write permissions") }, + {.code = LM_ERR_NotDir, .desc = _("specified path is not a directory") }, + {.code = LM_ERR_FailMkdir, .desc = _("failed to create the specified directory") }, + {.code = LM_ERR_PoolListBadDir, .desc = _("specified list extraction directory is not accessible") }, + {.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; diff --git a/src/util.c b/src/util.c index 2bd72f7..e7da499 100644 --- a/src/util.c +++ b/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); }