[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Remove needless -2 in log code. This was not an underflow ...
- To: or-cvs@freehaven.net
- Subject: [or-cvs] Remove needless -2 in log code. This was not an underflow ...
- From: nickm@seul.org (Nick Mathewson)
- Date: Mon, 29 Nov 2004 15:39:58 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Mon, 29 Nov 2004 15:40:21 -0500
- Reply-to: or-dev@freehaven.net
- Sender: owner-or-cvs@freehaven.net
Update of /home/or/cvsroot/tor/src/common
In directory moria.mit.edu:/tmp/cvs-serv29546/src/common
Modified Files:
log.c
Log Message:
Remove needless -2 in log code. This was not an underflow risk, sinze we only call format_msg from one place, where buf_len==10024
Index: log.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/log.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- log.c 29 Nov 2004 08:40:24 -0000 1.80
+++ log.c 29 Nov 2004 20:39:55 -0000 1.81
@@ -139,10 +139,18 @@
r = tor_vsnprintf(buf+n,buf_len-n,format,ap);
if (r < 0) {
- n = buf_len-2; /* XXX is this line redundant with the -=2 above,
- and also a source of underflow danger? */
- strlcpy(buf+buf_len-TRUNCATED_STR_LEN-1, TRUNCATED_STR,
- buf_len-(buf_len-TRUNCATED_STR_LEN-1));
+ /* The message was too long; overwrite the end of the buffer with
+ * "[...truncated]" */
+ if (buf_len >= TRUNCATED_STR_LEN) {
+ /* This is safe, since we have an extra character after buf_len
+ to hold the \0. */
+ strlcpy(buf+buf_len-TRUNCATED_STR_LEN, TRUNCATED_STR,
+ buf_len-(buf_len-TRUNCATED_STR_LEN-1));
+ }
+ /* Set 'n' to the end of the buffer, where we'll be writing \n\0.
+ * Since we already subtracted 2 from buf_len, this is safe.*/
+ n = buf_len;
+
} else {
n += r;
}