diff --git a/encfs/FileUtils.cpp b/encfs/FileUtils.cpp index 0431501..58e91a9 100644 --- a/encfs/FileUtils.cpp +++ b/encfs/FileUtils.cpp @@ -644,7 +644,7 @@ static Cipher::CipherAlgorithm selectCipherAlgorithm() { cout << "\n" << _("Enter the number corresponding to your choice: "); char answer[10]; char *res = fgets(answer, sizeof(answer), stdin); - int cipherNum = (res == nullptr ? 0 : atoi(answer)); + int cipherNum = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10)); cout << "\n"; if (cipherNum < 1 || cipherNum > (int)algorithms.size()) { @@ -688,7 +688,7 @@ static Interface selectNameCoding() { cout << "\n" << _("Enter the number corresponding to your choice: "); char answer[10]; char *res = fgets(answer, sizeof(answer), stdin); - int algNum = (res == nullptr ? 0 : atoi(answer)); + int algNum = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10)); cout << "\n"; if (algNum < 1 || algNum > (int)algorithms.size()) { @@ -755,7 +755,7 @@ static int selectKeySize(const Cipher::CipherAlgorithm &alg) { char answer[10]; char *res = fgets(answer, sizeof(answer), stdin); - int keySize = (res == nullptr ? 0 : atoi(answer)); + int keySize = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10)); cout << "\n"; keySize = alg.keyLength.closest(keySize); @@ -795,8 +795,8 @@ static int selectBlockSize(const Cipher::CipherAlgorithm &alg) { char *res = fgets(answer, sizeof(answer), stdin); cout << "\n"; - if (res != nullptr && atoi(answer) >= alg.blockSize.min()) { - blockSize = atoi(answer); + if (res != nullptr && (int)strtol(answer, nullptr, 10) >= alg.blockSize.min()) { + blockSize = (int)strtol(answer, nullptr, 10); } blockSize = alg.blockSize.closest(blockSize); @@ -900,7 +900,7 @@ static void selectBlockMAC(int *macBytes, int *macRandBytes, bool forceMac) { char *res = fgets(answer, sizeof(answer), stdin); cout << "\n"; - randSize = (res == nullptr ? 0 : atoi(answer)); + randSize = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10)); if (randSize < 0) { randSize = 0; } diff --git a/encfs/XmlReader.cpp b/encfs/XmlReader.cpp index 18d0cef..770cc96 100644 --- a/encfs/XmlReader.cpp +++ b/encfs/XmlReader.cpp @@ -23,6 +23,7 @@ #include // for remove_if #include // for NULL #include // for ifstream +#include #include // for shared_ptr #include // for ostringstream @@ -60,7 +61,15 @@ bool XmlValue::read(const char *path, int *out) const { return false; } - *out = atoi(value->text().c_str()); + char * e; + long lout = strtol(value->text().c_str(), &e, 10); + if (*e != '\0') { + return false; + } + if (lout < std::numeric_limits::min() || lout > std::numeric_limits::max()) { + return false; + } + *out = (int)lout; return true; } @@ -70,8 +79,9 @@ bool XmlValue::read(const char *path, long *out) const { return false; } - *out = atol(value->text().c_str()); - return true; + char * e; + *out = strtol(value->text().c_str(), &e, 10); + return (*e == '\0'); } bool XmlValue::read(const char *path, double *out) const { @@ -80,8 +90,9 @@ bool XmlValue::read(const char *path, double *out) const { return false; } - *out = atof(value->text().c_str()); - return true; + char * e; + *out = strtod(value->text().c_str(), &e); + return (*e == '\0'); } bool XmlValue::read(const char *path, bool *out) const { @@ -90,8 +101,9 @@ bool XmlValue::read(const char *path, bool *out) const { return false; } - *out = (atoi(value->text().c_str()) != 0); - return true; + char * e; + *out = (strtol(value->text().c_str(), &e, 10) != 0); + return (*e == '\0'); } bool XmlValue::readB64(const char *path, unsigned char *data,