[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Use strlcpy, not strncpy
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv943/src/common
Modified Files:
crypto.c util.c
Log Message:
Use strlcpy, not strncpy
Index: crypto.c
===================================================================
RCS file: /home/or/cvsroot/src/common/crypto.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- crypto.c 16 Oct 2004 22:28:11 -0000 1.113
+++ crypto.c 27 Oct 2004 06:03:28 -0000 1.114
@@ -462,8 +462,7 @@
len = BIO_get_mem_data(bio, &cp);
tor_assert(len >= 0);
s = tor_malloc(len+1);
- strncpy(s, cp, len);
- s[len] = '\0';
+ strlcpy(s, cp, len+1);
r = write_str_to_file(fname, s, 0);
BIO_free(bio);
free(s);
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.153
retrieving revision 1.154
diff -u -d -r1.153 -r1.154
--- util.c 27 Oct 2004 05:53:07 -0000 1.153
+++ util.c 27 Oct 2004 06:03:28 -0000 1.154
@@ -195,8 +195,7 @@
char *dup;
tor_assert(s);
dup = tor_malloc(n+1);
- strncpy(dup, s, n);
- dup[n] = 0;
+ strlcpy(dup, s, n+1);
return dup;
}
@@ -1770,7 +1769,8 @@
log_fn(LOG_WARN, "Couldn't find $HOME environment variable while expanding %s", filename);
return NULL;
}
- /* minus two characters for ~/, plus one for /, plus one for NUL. */
+ /* minus two characters for ~/, plus one for /, plus one for NUL.
+ * Round up to 16 in case we can't do math. */
len = strlen(home)+strlen(filename)+16;
result = tor_malloc(len);
snprintf(result,len,"%s/%s",home,filename+2);