neosys007 commented on code in PR #3357:
URL: https://github.com/apache/thrift/pull/3357#discussion_r2985155818


##########
compiler/cpp/src/thrift/main.cc:
##########
@@ -164,17 +165,25 @@ bool g_generator_failure = false;
  * Win32 doesn't have realpath, so use fallback implementation in that case,
  * otherwise this just calls through to realpath
  */
-char* saferealpath(const char* path, char* resolved_path) {
+char* saferealpath(const char* path, char* resolved_path, size_t 
resolved_path_size) {
 #ifdef _WIN32
   char buf[MAX_PATH];
   char* basename;
+  const char* source;
+  size_t source_len;
   DWORD len = GetFullPathNameA(path, MAX_PATH, buf, &basename);
   if (len == 0 || len > MAX_PATH - 1) {
-    strcpy(resolved_path, path);
+    source = path;
   } else {
-    strcpy(resolved_path, buf);
+    source = buf;
   }
 
+  source_len = strlen(source);
+  if (source_len >= resolved_path_size) {
+    return nullptr;
+  }
+  strcpy(resolved_path, source);

Review Comment:
   I would prefer not to truncate here. This path now rejects inputs that do 
not fit in the destination buffer, so strcpy() matches the intended semantics 
better than strncpy(): we want a full string copy after the explicit length 
check, not truncation or zero-padding.



-- 
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]

Reply via email to