You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2018/10/23 21:28:27 UTC
[mynewt-core] 01/03: test/runtest: Null-terminate segments of log
entry
This is an automated email from the ASF dual-hosted git repository.
ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 21dde7d715f8e0f2b339003c0f477d5b3eab45e4
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Tue Oct 2 18:39:40 2018 -0700
test/runtest: Null-terminate segments of log entry
Overly long segments (test case name, suite name, and message) were not
being null-terminated. This caused malformed JSON to be included in the
log.
---
test/runtest/src/runtest.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/test/runtest/src/runtest.c b/test/runtest/src/runtest.c
index 29b677e..3a19808 100644
--- a/test/runtest/src/runtest.c
+++ b/test/runtest/src/runtest.c
@@ -165,8 +165,10 @@ runtest_log_result(const char *msg, bool passed)
int m_len;
int len;
- /* str length of {"k":"","n":"","s":"","m":"","r":1}<token> */
- len = 35 + strlen(runtest_token);
+ /* str length of {"k":"","n":"","s":"","m":"","r":1}<token> plus three
+ * null-terminators.
+ */
+ len = 38 + strlen(runtest_token);
/* How much of the test name can we log? */
n_len = strlen(tu_case_name);
@@ -175,7 +177,8 @@ runtest_log_result(const char *msg, bool passed)
}
len += n_len;
n = buf;
- strncpy(n, tu_case_name, n_len + 1);
+ strncpy(n, tu_case_name, n_len);
+ n[n_len] = '\0';
/* How much of the suite name can we log? */
s_len = strlen(runtest_current_ts->ts_name);
@@ -184,7 +187,8 @@ runtest_log_result(const char *msg, bool passed)
}
len += s_len;
s = n + n_len + 2;
- strncpy(s, runtest_current_ts->ts_name, s_len + 1);
+ strncpy(s, runtest_current_ts->ts_name, s_len);
+ s[s_len] = '\0';
/* How much of the message can we log? */
m_len = strlen(msg);
@@ -192,7 +196,8 @@ runtest_log_result(const char *msg, bool passed)
m_len = LOG_PRINTF_MAX_ENTRY_LEN - len - 1;
}
m = s + s_len + 2;
- strncpy(m, msg, m_len + 1);
+ strncpy(m, msg, m_len);
+ m[m_len] = '\0';
/* XXX Hack to allow the idle task to run and update the timestamp. */
os_time_delay(1);