diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2019-06-08 14:54:39 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2019-06-08 14:54:39 +0200 |
commit | e907b2c316ab5261c5acccd08ba8a32d32efd50c (patch) | |
tree | adb5e7e8a504bf782bc7bd02f69a9c2b529dd7f9 | |
parent | cd195e9bafd6d31807e6b187039996f541982d48 (diff) | |
download | embedlog-e907b2c316ab5261c5acccd08ba8a32d32efd50c.tar.gz embedlog-e907b2c316ab5261c5acccd08ba8a32d32efd50c.tar.bz2 embedlog-e907b2c316ab5261c5acccd08ba8a32d32efd50c.zip |
src/el-private.h: add missing EL_PRE_FUNCINFO_LEN to EL_PRE_LEN calc
EL_PRE_FUNCINFO_LEN was missing when calculating EL_PRE_LEN, which
is used to calculate EL_BUF_MAX. Without that, buffer was too small
to hold all print information, which could result in buffer overflow.
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r-- | src/el-private.h | 4 | ||||
-rw-r--r-- | tst/test-el-print.c | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/el-private.h b/src/el-private.h index 21d10ba..b85da02 100644 --- a/src/el-private.h +++ b/src/el-private.h @@ -249,8 +249,8 @@ extern struct el g_el; # define EL_PREFIX_LEN 0 #endif -#define EL_PRE_LEN (EL_PRE_TS_MAX + EL_PRE_FINFO_LEN + EL_PREFIX_LEN + \ - EL_PRE_LEVEL_LEN) +#define EL_PRE_LEN (EL_PRE_TS_MAX + EL_PRE_FINFO_LEN + EL_PRE_FUNCINFO_LEN + \ + EL_PREFIX_LEN + EL_PRE_LEVEL_LEN) /* ========================================================================== diff --git a/tst/test-el-print.c b/tst/test-el-print.c index e5abe62..1bcfcfa 100644 --- a/tst/test-el-print.c +++ b/tst/test-el-print.c @@ -484,7 +484,7 @@ static int print_check(void) } tmp[i] = '\0'; - if (strcmp(tmp, expected.func) != 0) + if (strncmp(tmp, expected.func, EL_FUNCLEN_MAX) != 0) { /* function is different than what we expected */ @@ -1236,6 +1236,7 @@ static void print_truncate_with_all_options(void) { char msg[EL_LOG_MAX + 3]; char finfo[EL_FLEN_MAX + 3]; + char funcinfo[EL_FUNCLEN_MAX + 3]; char prefix[EL_PREFIX_MAX + 3]; size_t fline; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ @@ -1245,14 +1246,17 @@ static void print_truncate_with_all_options(void) el_option(EL_TS_FRACT, EL_TS_FRACT_NS); el_option(EL_TS_TM, EL_TS_TM_REALTIME); el_option(EL_FINFO, 1); + el_option(EL_FUNCINFO, 1); el_option(EL_COLORS, 1); el_option(EL_PREFIX, prefix); el_option(EL_PRINT_LEVEL, 1); memset(msg, 'a', sizeof(msg)); memset(finfo, 'b', sizeof(finfo)); memset(prefix, 'c', sizeof(prefix)); + memset(funcinfo, 'f', sizeof(funcinfo)); finfo[sizeof(finfo) - 1] = '\0'; prefix[sizeof(prefix) - 1] = '\0'; + funcinfo[sizeof(funcinfo) - 1] = '\0'; fline = (size_t)pow(10, EL_PRE_FINFO_LINE_MAX_LEN + 2) - 1; msg[sizeof(msg) - 1] = '\0'; msg[sizeof(msg) - 2] = '3'; @@ -1261,9 +1265,10 @@ static void print_truncate_with_all_options(void) msg[sizeof(msg) - 4] = '0'; add_log(ELI, "not truncated"); - add_log(finfo, fline, "print_truncate_with_all_options", EL_FATAL, msg); + add_log(finfo, fline, funcinfo, EL_FATAL, msg); msg[sizeof(msg) - 3] = '\0'; + puts(logbuf); mt_fok(print_check()); } |