From: oetiker Date: Sat, 16 Dec 2006 16:14:43 +0000 (+0000) Subject: add missing \0 to the end of several strncpy strings X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d574ec421c236ce95b41de70daa2b1eddcb53033;p=rrdtool-all.git add missing \0 to the end of several strncpy strings git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2@938 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/program/src/rrd_error.c b/program/src/rrd_error.c index a102b1fe..68fcc8e6 100644 --- a/program/src/rrd_error.c +++ b/program/src/rrd_error.c @@ -80,6 +80,7 @@ rrd_set_error_r(struct rrd_context *rrd_ctx, char *fmt, ...) va_start(argp, fmt); #ifdef HAVE_VSNPRINTF vsnprintf((char *)rrd_ctx->rrd_error, rrd_ctx->len, fmt, argp); + rrd_ctx->rrd_error[rrd_ctx->len]='\0'; #else vsprintf((char *)rrd_ctx->rrd_error, fmt, argp); #endif @@ -110,7 +111,6 @@ rrd_new_context(void) { (struct rrd_context *) malloc(sizeof(struct rrd_context)); if (rrd_ctx) { - rrd_ctx->len = 0; rrd_ctx->rrd_error = malloc(MAXLEN+10); rrd_ctx->lib_errstr = malloc(ERRBUFLEN+10); if (rrd_ctx->rrd_error && rrd_ctx->lib_errstr) { diff --git a/program/src/rrd_thread_safe.c b/program/src/rrd_thread_safe.c index c06da050..bccea99f 100644 --- a/program/src/rrd_thread_safe.c +++ b/program/src/rrd_thread_safe.c @@ -61,6 +61,7 @@ const char *rrd_strerror(int err) { ctx = rrd_get_context(); pthread_mutex_lock(&mtx); strncpy(ctx->lib_errstr, strerror(err), ctx->errlen); + ctx->lib_errstr[ctx->errlen]='\0'; pthread_mutex_unlock(&mtx); return ctx->lib_errstr; } diff --git a/program/src/rrd_thread_safe_nt.c b/program/src/rrd_thread_safe_nt.c index 8f68ea39..105507f2 100644 --- a/program/src/rrd_thread_safe_nt.c +++ b/program/src/rrd_thread_safe_nt.c @@ -63,7 +63,8 @@ const char *rrd_strerror(int err) { EnterCriticalSection(&CriticalSection); strncpy(ctx->lib_errstr, strerror(err), ctx->errlen); - LeaveCriticalSection(&CriticalSection); + ctx->lib_errstr[ctx->errlen] = '\0'; + LeaveCriticalSection(&CriticalSection); return ctx->lib_errstr; }