fix bad string access beyond trailing nullbyte

This commit is contained in:
Thomas Schoebel-Theuer 2011-11-14 16:00:25 +01:00 committed by Thomas Schoebel-Theuer
parent eb8c9ddac4
commit a861bdf5b7
2 changed files with 2 additions and 1 deletions

View File

@ -26,6 +26,7 @@ extern void _brick_mem_free(void *data, int line);
#define BRICK_STRING_LEN 1024 /* default value when len == 0 */
#define brick_string_alloc(_len_) _brick_string_alloc(_len_, __LINE__)
#define brick_strndup(_orig_,_len_) ({ char *_res_ = _brick_string_alloc((_len_) + 1, __LINE__); if (_res_) { strncpy(_res_, _orig_, (_len_)); _res_[_len_] = '\0';} _res_; })
#define brick_strdup(_orig_) ({ int _len_ = strlen(_orig_); char *_res_ = _brick_string_alloc(_len_ + 1, __LINE__); if (_res_) { strncpy(_res_, _orig_, _len_ + 1); } _res_; })
extern char *_brick_string_alloc(int len, int line);
#define brick_string_free(_data_) _brick_string_free(_data_, __LINE__)

View File

@ -2985,7 +2985,7 @@ static int light_checker(struct mars_dent *parent, const char *_name, int namlen
int class;
int status = -2;
#ifdef MARS_DEBUGGING
const char *name = brick_strdup(_name);
const char *name = brick_strndup(_name, namlen);
if (!name)
return -ENOMEM;
#else