summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Herrmann <fherrmann@de.adit-jv.com>2020-01-14 17:18:46 +0100
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2020-07-06 10:04:07 +0900
commit0ae98e7b46f13d415e051a7acdfd7d703c5c25f9 (patch)
tree80cdb59ff4da84880dcc09224fcdc76009313751 /src
parent676e8fc1ba927dc84df82b508d796e31d9fd120c (diff)
downloadDLT-daemon-0ae98e7b46f13d415e051a7acdfd7d703c5c25f9.tar.gz
snprintf ret > 0 is not always an error
snprintf returns the size the resulting string would take. In order to detect truncation, this size needs to be checked against the buffer size. Signed-off-by: Felix Herrmann <fherrmann@de.adit-jv.com> Signed-off-by: KHANH LUONG HONG DUY <khanh.luonghongduy@vn.bosch.com>
Diffstat (limited to 'src')
-rw-r--r--src/daemon/dlt-daemon.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index fd46795..e4039a2 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -243,6 +243,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
char value[value_length];
char *pch;
const char *filename;
+ ssize_t n;
/* set default values for configuration */
daemon_local->flags.sharedMemorySize = DLT_SHM_SIZE;
@@ -254,11 +255,12 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.loggingMode = DLT_LOG_TO_CONSOLE;
daemon_local->flags.loggingLevel = LOG_INFO;
- if (snprintf(daemon_local->flags.loggingFilename,
+ n = snprintf(daemon_local->flags.loggingFilename,
sizeof(daemon_local->flags.loggingFilename),
- "%s/dlt.log", dltFifoBaseDir) != 0) {
- dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error %s\n", __func__,
- daemon_local->flags.loggingFilename);
+ "%s/dlt.log", dltFifoBaseDir);
+ if (n < 0 || (size_t)n > sizeof(daemon_local->flags.loggingFilename)) {
+ dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%d) %s\n",
+ __func__, n, daemon_local->flags.loggingFilename);
}
daemon_local->timeoutOnSend = 4;
@@ -1500,9 +1502,13 @@ void dlt_daemon_exit_trigger()
{
char tmp[DLT_PATH_MAX] = { 0 };
- if (snprintf(tmp, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir) != 0) {
- dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error %s\n", __func__, tmp);
+ ssize_t n;
+ n = snprintf(tmp, DLT_PATH_MAX, "%s/dlt", dltFifoBaseDir);
+ if (n < 0 || (size_t)n > DLT_PATH_MAX) {
+ dlt_vlog(LOG_WARNING, "%s: snprintf truncation/error(%d) %s\n",
+ __func__, n, tmp);
}
+
(void)unlink(tmp);
/* stop event loop */