[Lldb-commits] [PATCH] Fix FileSpec::GetPath to return null-terminated strings
Greg Clayton
clayborg at gmail.com
Thu Feb 26 10:38:39 PST 2015
Fix some incorrect usage of snprintf.
================
Comment at: source/API/SBFileSpec.cpp:97
@@ -96,3 +96,3 @@
size_t result_length = std::min(dst_len-1, result.size());
- ::strncpy(dst_path, result.c_str(), result_length + 1);
+ ::snprintf(dst_path, result_length + 1, "%s", result.c_str());
return result_length;
----------------
This should be
```
::snprintf(dst_path, dst_len, "%s", result.c_str());
```
snprintf takes the output buffer and output buffer size as the first two arguments. it will also ensure NULL termination even if we go over the buffer size.
================
Comment at: source/Host/common/FileSpec.cpp:798
@@ -797,3 +797,3 @@
size_t result_length = std::min(path_max_len-1, result.length());
- ::strncpy(path, result.c_str(), result_length + 1);
+ ::snprintf(path, result_length + 1, "%s", result.c_str());
return result_length;
----------------
this should be:
```
::snprintf(path, path_max_len, "%s", result.c_str());
```
================
Comment at: source/Host/common/SocketAddress.cpp:51
@@ -50,4 +50,3 @@
{
- strncpy(dst, formatted, size);
- return dst;
+ return ::strcpy(dst, formatted);
}
----------------
Why did you switch to using an unsafe strcpy() here? You can overflow "dst" no?
================
Comment at: source/Host/common/SocketAddress.cpp:66
@@ -66,4 +65,3 @@
{
- strncpy(dst,tmp,size);
- return dst;
+ return ::strcpy(dst, tmp);
}
----------------
Why did you switch to using an unsafe strcpy() here? You can overflow "dst" no?
================
Comment at: source/lldb.cpp:373
@@ -372,3 +372,3 @@
- ::strncpy(g_version_string, version_string, version_len);
+ ::snprintf(g_version_string, version_len + 1, "%s", version_string);
}
----------------
This should be:
```
::snprintf(g_version_string, sizeof(g_version_string), "%s", version_string);
```
http://reviews.llvm.org/D7553
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the lldb-commits
mailing list