GauthamBanasandra commented on code in PR #4287:
URL: https://github.com/apache/hadoop/pull/4287#discussion_r873393779


##########
hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs-chmod/hdfs-chmod.cc:
##########
@@ -140,8 +140,17 @@ bool Chmod::HandlePath(const std::string &permissions, 
const bool recursive,
   /*
    * strtol is reading the value with base 8, NULL because we are reading in
    * just one value.
+   *
+   * The strtol function may result in errors so check for that before 
typecasting.
    */
-  auto perm = static_cast<uint16_t>(strtol(permissions.c_str(), nullptr, 8));
+  errno = 0;
+  long result = strtol(permissions.c_str(), nullptr, 8);
+  /*
+   * The errno is set to ERANGE incase the string doesn't fit in long
+   * Also, the result is set to 0, in case conversion is not possible
+   */
+  if ((errno == ERANGE) || result == 0) return false;

Review Comment:
   One solution that I thought of was to use 
[std::all_of](https://en.cppreference.com/w/cpp/algorithm/all_any_none_of) to 
check if `permissions` contains only 0 and then bypass the `result == 0` if 
that happens to be the case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to