From: Lukasz Pawelczyk Date: Mon, 11 Sep 2017 11:14:45 +0000 (+0200) Subject: Notify and throw if cryptsetup fails X-Git-Tag: submit/tizen/20170918.080130~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=851249cf0ba7de6ec06871d993ed54ae81013247;p=platform%2Fcore%2Fsecurity%2Fode.git Notify and throw if cryptsetup fails Fix bracket's style in the same function Change-Id: I22973c995cc489124c57acac23d531605e9f3700 --- diff --git a/server/engine/encryption/cryptsetup-engine.cpp b/server/engine/encryption/cryptsetup-engine.cpp index 5ad0f39..ef7d32b 100644 --- a/server/engine/encryption/cryptsetup-engine.cpp +++ b/server/engine/encryption/cryptsetup-engine.cpp @@ -44,21 +44,24 @@ void forkAndWrite(const char *const* argv, const CryptsetupEngine::data *d) // pipe int pipefd[2]; if (d != NULL) { - if (0 != pipe(pipefd)) + if (0 != pipe(pipefd)) { throw runtime::Exception("pipe() failed:" + std::to_string(errno)); + } } pid_t pid = ::fork(); - if (pid == -1) + if (pid == -1) { throw runtime::Exception("fork() failed: " + std::to_string(errno)); + } if (pid == 0) { if (d != NULL) { ::close(pipefd[1]); int fd = TEMP_FAILURE_RETRY(dup2(pipefd[0], STDIN_FILENO)); - if (fd == -1) + if (fd == -1) { exit(EXIT_FAILURE); + } ::close(pipefd[0]); } @@ -72,8 +75,9 @@ void forkAndWrite(const char *const* argv, const CryptsetupEngine::data *d) // write the pipefd[1] ssize_t ret = TEMP_FAILURE_RETRY(write(pipefd[1], d->data(), d->size())); - if (ret < 0 || (size_t)ret != d->size()) + if (ret < 0 || (size_t)ret != d->size()) { throw runtime::Exception("write() failed"); + } ::close(pipefd[1]); } @@ -84,6 +88,13 @@ void forkAndWrite(const char *const* argv, const CryptsetupEngine::data *d) throw runtime::Exception("waitpid() failed: " + std::to_string(errno)); } } + if (!WIFEXITED(status)) { + throw runtime::Exception(std::string(argv[0]) + " terminated abnormally"); + } + int ret = WEXITSTATUS(status); + if (ret != 0) { + throw runtime::Exception(std::string(argv[0]) + " failed with: " + std::to_string(ret)); + } } } // anonymous namespace