infra: fix potential fault

Very old idiotic bug.
Under some circumstances, a byte beyond the end of a non-null-terminated
string (such as produced by the VFS) might be read, potentially leading
to a page fault just one byte after a page border.
This commit is contained in:
Thomas Schoebel-Theuer 2015-12-17 09:28:15 +01:00 committed by Thomas Schoebel-Theuer
parent 25d954051b
commit d18c60f232

View File

@ -152,7 +152,7 @@ extern void _brick_mem_free(void *data, int line);
char *_res_ = _brick_string_alloc((_len_) + 1, __LINE__); \ char *_res_ = _brick_string_alloc((_len_) + 1, __LINE__); \
_res_ = brick_mark_nonnull(_res_); \ _res_ = brick_mark_nonnull(_res_); \
if (_res_) { \ if (_res_) { \
strncpy(_res_, (_orig_), (_len_) + 1); \ strncpy(_res_, (_orig_), (_len_)); \
/* always null-terminate for safety */ \ /* always null-terminate for safety */ \
_res_[_len_] = '\0'; \ _res_[_len_] = '\0'; \
} \ } \