[Cluster-devel] [PATCH 2/4] liblogthread: make sure there is space for \0 end string
Fabio M. Di Nitto
fdinitto at redhat.com
Mon Oct 10 08:45:19 UTC 2011
Spotted by Coverity Scan
Signed-off-by: Fabio M. Di Nitto <fdinitto at redhat.com>
---
:100644 100644 4f8354a... 384f042... M common/liblogthread/liblogthread.c
common/liblogthread/liblogthread.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/common/liblogthread/liblogthread.c b/common/liblogthread/liblogthread.c
index 4f8354a..384f042 100644
--- a/common/liblogthread/liblogthread.c
+++ b/common/liblogthread/liblogthread.c
@@ -128,7 +128,7 @@ static void _logt_print(int level, char *buf)
head_ent = head_ent % num_ents;
pending_ents++;
- strncpy(e->str, buf, ENTRY_STR_LEN);
+ strncpy(e->str, buf, ENTRY_STR_LEN - 1);
e->level = level;
e->time = time(NULL);
out:
@@ -172,9 +172,9 @@ static void _conf(const char *name, int mode, int syslog_facility,
logt_syslog_priority = syslog_priority;
logt_logfile_priority = logfile_priority;
if (name)
- strncpy(logt_name, name, PATH_MAX);
+ strncpy(logt_name, name, PATH_MAX - 1);
if (logfile)
- strncpy(logt_logfile, logfile, PATH_MAX);
+ strncpy(logt_logfile, logfile, PATH_MAX - 1);
if (logt_mode & LOG_MODE_OUTPUT_FILE && logt_logfile[0]) {
if (logt_logfile_fp) {
@@ -255,11 +255,11 @@ int logt_reinit(void)
memset(name_tmp, 0, sizeof(name_tmp));
memset(file_tmp, 0, sizeof(file_tmp));
- strncpy(name_tmp, logt_name, sizeof(name_tmp));
+ strncpy(name_tmp, logt_name, sizeof(name_tmp) - 1);
if (!strlen(name_tmp))
return -1;
if (strlen(logt_logfile))
- strncpy(file_tmp, logt_logfile, sizeof(file_tmp));
+ strncpy(file_tmp, logt_logfile, sizeof(file_tmp) - 1);
return logt_init(name_tmp, logt_mode, logt_syslog_facility,
logt_syslog_priority, logt_logfile_priority,
--
1.7.4.4
More information about the Cluster-devel
mailing list