base: Fix 'doGzipLoad' str manipulation
When running `scons build/ALL/gem5.opt --with-ubsan`, with GCC, the
following error was returned:
```
[ CXX] src/base/loader/image_file_data.cc -> ALL/base/loader/image_file_data.o
In file included from /usr/include/string.h:535,
from /usr/include/c++/11/cstring:42,
from src/base/cprintf_formats.hh:33,
from src/base/cprintf.hh:38,
from src/base/logging.hh:49,
from src/base/loader/image_file_data.cc:40:
In function ‘char* strcpy(char*, const char*)’,
inlined from ‘int gem5::loader::doGzipLoad(int)’ at src/base/loader/image_file_data.cc:70:11,
inlined from ‘gem5::loader::ImageFileData::ImageFileData(const string&)’ atsrc/base/loader/image_file_data.cc:116:24:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:79:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ offset [0, 19] is out of the bounds [0, 0] [-Werror=array-bounds]
79 | return __builtin___strcpy_chk (__dest, __src, __glibc_objsize (__dest));
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
scons: *** [build/ALL/base/loader/image_file_data.o] Error 1
scons: building terminated because of errors.
```
I do not know the exact issue but using strcpy in this way (i.e.
`strcpy(char_pointer + offset, string)`) appears to trigger this error
with the undefined behavior sanitizer. The fix in this patch replaces
this with `strcat`.
Change-Id: I1a0c50c9022adc841e175aad0fe2247bfcb29d71
This commit is contained in:
@@ -67,7 +67,7 @@ doGzipLoad(int fd)
|
||||
size_t tmp_len = strlen(P_tmpdir);
|
||||
char *tmpnam = (char*) malloc(tmp_len + 20);
|
||||
strcpy(tmpnam, P_tmpdir);
|
||||
strcpy(tmpnam+tmp_len, "/gem5-gz-obj-XXXXXX"); // 19 chars
|
||||
strcat(tmpnam, "/gem5-gz-obj-XXXXXX"); // concat 19 chars
|
||||
fd = mkstemp(tmpnam); // repurposing fd variable for output
|
||||
if (fd < 0) {
|
||||
free(tmpnam);
|
||||
|
||||
Reference in New Issue
Block a user