[or-cvs] fix a segfault on truncated log lines

Roger Dingledine arma at seul.org
Fri Sep 19 09:30:36 UTC 2003


Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/common

Modified Files:
	log.c 
Log Message:
fix a segfault on truncated log lines


Index: log.c
===================================================================
RCS file: /home/or/cvsroot/src/common/log.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- log.c	16 Sep 2003 17:58:36 -0000	1.12
+++ log.c	19 Sep 2003 09:30:34 -0000	1.13
@@ -49,14 +49,22 @@
   my_gettimeofday(&now);
   t = (time_t)now.tv_sec;
   
-  n  = strftime(buf, buf_len, "%b %d %H:%M:%S", localtime(&t));
+  n = strftime(buf, buf_len, "%b %d %H:%M:%S", localtime(&t));
   n += snprintf(buf+n, buf_len-n,
-		".%.3ld [%s] ", 
-		(long)now.tv_usec / 1000, sev_to_string(severity));
-  if (funcname)
+                ".%.3ld [%s] ", 
+                (long)now.tv_usec / 1000, sev_to_string(severity));
+  if(n > buf_len)
+    n = buf_len; /* the *nprintf funcs return how many bytes they
+                  * _would_ print, if the output is truncated */
+  if (funcname) {
     n += snprintf(buf+n, buf_len-n, "%s(): ", funcname);
+    if(n > buf_len)
+      n = buf_len;
+  }
 
   n += vsnprintf(buf+n,buf_len-n,format,ap);
+  if(n > buf_len)
+    n = buf_len;
   buf[n]='\n';
   buf[n+1]='\0';
 }



More information about the tor-commits mailing list