aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-03-17 07:28:09 +0000
committerNick Mathewson <nickm@torproject.org>2004-03-17 07:28:09 +0000
commit971b002d935155abd56d0b01fe5e284f63439b99 (patch)
treec31c349097cf981b9294f226534608b750c83f92 /src/common/util.c
parentd9a8e317e435222da6dd670049b1f73654bbcca2 (diff)
downloadtor-971b002d935155abd56d0b01fe5e284f63439b99.tar
tor-971b002d935155abd56d0b01fe5e284f63439b99.tar.gz
Include strlcpy and strlcat where not available, so our string ops can be less error-prone.
svn:r1289
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 9194602bd..87cdd97ce 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -8,6 +8,13 @@
#include <sys/utsname.h>
#endif
+#ifndef HAVE_STRLCPY
+#include "strlcpy.c"
+#endif
+#ifndef HAVE_STRLCAT
+#include "strlcat.c"
+#endif
+
/*
* Memory wrappers
*/
@@ -568,12 +575,11 @@ write_str_to_file(const char *fname, const char *str)
char tempname[1024];
int fd;
FILE *file;
- if (strlen(fname) > 1000) {
- log(LOG_WARN, "Filename %s is too long.", fname);
+ if ((strlcpy(tempname,fname,1024) >= 1024) ||
+ (strlcat(tempname,".tmp",1024) >= 1024)) {
+ log(LOG_WARN, "Filename %s.tmp too long (>1024 chars)", fname);
return -1;
}
- strcpy(tempname,fname);
- strcat(tempname,".tmp");
if ((fd = open(tempname, O_WRONLY|O_CREAT|O_TRUNC, 0600)) < 0) {
log(LOG_WARN, "Couldn't open %s for writing: %s", tempname,
strerror(errno));