From: sangwan.kwon Date: Wed, 13 Sep 2017 04:49:02 +0000 (-0400) Subject: Replace std::rewind to std::fseek X-Git-Tag: submit/tizen/20171026.071605~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=549806e4726c0bae448d189fcfcd2bd60bccc845;p=platform%2Fcore%2Fsecurity%2Ftrust-anchor.git Replace std::rewind to std::fseek std::rewind cannot handle error indicators. Change-Id: I8c4006c5378a19c6e761708df619f1d77261d8bd Signed-off-by: sangwan.kwon --- diff --git a/src/certificate.cpp b/src/certificate.cpp index 103c864..13a8f70 100644 --- a/src/certificate.cpp +++ b/src/certificate.cpp @@ -58,7 +58,10 @@ std::string Certificate::getSubjectNameHash() const X509Ptr x509(::PEM_read_X509(fp.get(), NULL, NULL, NULL), ::X509_free); if (x509 == nullptr) { - ::rewind(fp.get()); + std::fseek(fp.get(), 0L, SEEK_SET); + if (std::ferror(fp.get())) + throw std::logic_error("Failed to set the position as beginning."); + x509 = X509Ptr(::PEM_read_X509_AUX(fp.get(), NULL, NULL, NULL), ::X509_free); } diff --git a/src/file-system.cpp b/src/file-system.cpp index ec1ab6d..2171638 100644 --- a/src/file-system.cpp +++ b/src/file-system.cpp @@ -45,12 +45,18 @@ std::string File::read(const std::string &path) throw std::invalid_argument("Failed to open [" + path + "]."); std::fseek(fp.get(), 0L, SEEK_END); + if (std::ferror(fp.get())) + throw std::logic_error("Failed to set the position as end [" + path + "]."); + unsigned int fsize = std::ftell(fp.get()); - std::rewind(fp.get()); + std::fseek(fp.get(), 0L, SEEK_SET); + if (std::ferror(fp.get())) + throw std::logic_error("Failed to set the position as beginning [" + path + "]."); std::string buff(fsize, 0); if (fsize != std::fread(static_cast(&buff[0]), 1, fsize, fp.get())) throw std::logic_error("Failed to read [" + path + "]"); + return buff; }