]> arthur.barton.de Git - netatalk.git/commitdiff
check the return value of nprintf functions
authordidg <didg>
Mon, 19 Oct 2009 11:15:45 +0000 (11:15 +0000)
committerdidg <didg>
Mon, 19 Oct 2009 11:15:45 +0000 (11:15 +0000)
libatalk/util/logger.c
libatalk/vfs/vfs.c

index 5883634cd7d9c89cc8a195bd6a34cdd4e8ed9183..60361371c05be64b7e7f311bdf5597117d68d5c5 100644 (file)
@@ -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<num_logtype_strings) {
         templen = snprintf(ptr, len, "%s", arr_logtype_strings[logtype]);
+        if (templen == -1 || templen >= 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;
index 2f45b5c3ec8ff65e15844b0d85cb1e6d99197cb3..b160646e2b076fc0cb95239806f903e655f379f2 100644 (file)
@@ -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)