From: didg Date: Mon, 19 Oct 2009 11:15:45 +0000 (+0000) Subject: check the return value of nprintf functions X-Git-Tag: before-ipv6~70 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=247ea1dd3c1194cfd8b5beb86b9a8d5c53d68590 check the return value of nprintf functions --- diff --git a/libatalk/util/logger.c b/libatalk/util/logger.c index 5883634c..60361371 100644 --- a/libatalk/util/logger.c +++ b/libatalk/util/logger.c @@ -162,6 +162,9 @@ static void generate_message_details(char *message_details_buffer, ptr += templen; templen = snprintf(ptr, len, "%06u ", (int)tv.tv_usec); + if (templen == -1 || templen >= len) + return; + len -= templen; ptr += templen; @@ -174,6 +177,8 @@ static void generate_message_details(char *message_details_buffer, /* PID */ pid = getpid(); templen = snprintf(ptr, len, "[%d]", pid); + if (templen == -1 || templen >= len) + return; len -= templen; ptr += templen; @@ -184,7 +189,7 @@ static void generate_message_details(char *message_details_buffer, templen = snprintf(ptr, len, " {%s:%d}", basename + 1, log_src_linenumber); else templen = snprintf(ptr, len, " {%s:%d}", log_src_filename, log_src_linenumber); - if (templen >= len) + if (templen == -1 || templen >= len) return; len -= templen; ptr += templen; @@ -195,12 +200,16 @@ static void generate_message_details(char *message_details_buffer, templen = snprintf(ptr, len, " (D%d:", loglevel - 1); else templen = snprintf(ptr, len, " (%c:", arr_loglevel_chars[loglevel]); + if (templen == -1 || templen >= len) + return; len -= templen; ptr += templen; /* Errortype */ if (logtype= len) + return; len -= templen; ptr += templen; } @@ -398,7 +407,7 @@ void make_log_entry(enum loglevels loglevel, enum logtypes logtype, va_end(args); /* Append \n */ - if (len >= MAXLOGSIZE) + if (len ==-1 || len >= MAXLOGSIZE) /* vsnprintf hit the buffer size*/ temp_buffer[MAXLOGSIZE-2] = '\n'; else { @@ -448,7 +457,7 @@ void make_syslog_entry(enum loglevels loglevel, enum logtypes logtype _U_, char va_start(args, message); vsnprintf(log_buffer, sizeof(log_buffer), message, args); va_end(args); - + log_buffer[MAXLOGSIZE -1] = 0; syslog(get_syslog_equivalent(loglevel), "%s", log_buffer); inlog = 0; diff --git a/libatalk/vfs/vfs.c b/libatalk/vfs/vfs.c index 2f45b5c3..b160646e 100644 --- a/libatalk/vfs/vfs.c +++ b/libatalk/vfs/vfs.c @@ -318,11 +318,13 @@ static int RF_solaris_acl(VFS_FUNC_ARGS_ACL) { static char buf[ MAXPATHLEN + 1]; struct stat st; + int len; if ((stat(path, &st)) != 0) return -1; if (S_ISDIR(st.st_mode)) { - if ((snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path)) < 0) + len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path); + if (len < 0 || len >= MAXPATHLEN) return -1; /* set acl on .AppleDouble dir first */ if ((acl(buf, cmd, count, aces)) != 0) @@ -342,9 +344,11 @@ static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL) { int ret; static char buf[ MAXPATHLEN + 1]; + int len; if (dir) { - if ((snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path)) < 0) + len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path); + if (len < 0 || len >= MAXPATHLEN) return AFPERR_MISC; /* remove ACL from .AppleDouble/.Parent first */ if ((ret = remove_acl(vol->vfs->ad_path(path, ADFLAGS_DIR))) != AFP_OK)