diff options
author | Ilia K <ki.stfu@gmail.com> | 2015-02-27 19:43:08 +0000 |
---|---|---|
committer | Ilia K <ki.stfu@gmail.com> | 2015-02-27 19:43:08 +0000 |
commit | 686b1fe65ae90f531d5010b3c6b47b479d4b7ccd (patch) | |
tree | 5f634785f9fc1e7a88b587c29d43b13bae9afc2c /lldb/source/lldb.cpp | |
parent | 79e6c74981f4755ed55b38175d8cd34ec91395b1 (diff) | |
download | bcm5719-llvm-686b1fe65ae90f531d5010b3c6b47b479d4b7ccd.tar.gz bcm5719-llvm-686b1fe65ae90f531d5010b3c6b47b479d4b7ccd.zip |
Fix FileSpec::GetPath to return null-terminated strings
Summary:
Before this fix the FileSpec::GetPath() returned string which might be without '\0' at the end.
It could have happened if the size of buffer for path was less than actual path.
Test case:
```
FileSpec test("/path/to/file", false);
char buf[]="!!!!!!";
test.GetPath(buf, 3);
```
Before fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/pa!!!"
```
After fix:
```
233 FileSpec test("/path/to/file", false);
234 char buf[]="!!!!!!";
235 test.GetPath(buf, 3);
236
-> 237 if (core_file)
238 {
239 if (!core_file.Exists())
240 {
(lldb) print buf
(char [7]) $0 = "/p"
```
Reviewers: zturner, abidh, clayborg
Reviewed By: abidh, clayborg
Subscribers: tberghammer, vharron, lldb-commits, clayborg, zturner, abidh
Differential Revision: http://reviews.llvm.org/D7553
llvm-svn: 230787
Diffstat (limited to 'lldb/source/lldb.cpp')
-rw-r--r-- | lldb/source/lldb.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lldb/source/lldb.cpp b/lldb/source/lldb.cpp index 129c5ee05a6..f7eca36deaa 100644 --- a/lldb/source/lldb.cpp +++ b/lldb/source/lldb.cpp @@ -364,13 +364,13 @@ lldb_private::GetVersion () const char *newline_loc = strchr(version_string, '\n'); - size_t version_len = sizeof(g_version_string); + size_t version_len = sizeof(g_version_string) - 1; if (newline_loc && (newline_loc - version_string < static_cast<ptrdiff_t>(version_len))) version_len = newline_loc - version_string; - ::strncpy(g_version_string, version_string, version_len); + ::snprintf(g_version_string, version_len + 1, "%s", version_string); } return g_version_string; |