[or-cvs] Include strlcpy and strlcat where not available, so our str...

Nick Mathewson nickm at seul.org
Wed Mar 17 07:28:11 UTC 2004


Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv26407/src/common

Modified Files:
	Makefile.am util.c util.h 
Added Files:
	strlcat.c strlcpy.c 
Log Message:
Include strlcpy and strlcat where not available, so our string ops can be less error-prone.

--- NEW FILE: strlcat.c ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: strlcpy.c ---
(This appears to be a binary file; contents omitted.)

Index: Makefile.am
===================================================================
RCS file: /home/or/cvsroot/src/common/Makefile.am,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- Makefile.am	4 Sep 2003 16:05:08 -0000	1.15
+++ Makefile.am	17 Mar 2004 07:28:09 -0000	1.16
@@ -6,4 +6,3 @@
 libor_a_SOURCES = log.c crypto.c fakepoll.c util.c aes.c tortls.c
 
 noinst_HEADERS = log.h crypto.h fakepoll.h test.h util.h aes.h torint.h tortls.h
-

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- util.c	15 Mar 2004 04:00:11 -0000	1.61
+++ util.c	17 Mar 2004 07:28:09 -0000	1.62
@@ -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 @@
   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));

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- util.h	14 Mar 2004 18:07:46 -0000	1.35
+++ util.h	17 Mar 2004 07:28:09 -0000	1.36
@@ -32,6 +32,9 @@
 #define INLINE inline
 #endif
 
+size_t strlcat(char *dst, const char *src, size_t siz);
+size_t strlcpy(char *dst, const char *src, size_t siz);
+
 void *tor_malloc(size_t size);
 void *tor_malloc_zero(size_t size);
 void *tor_realloc(void *ptr, size_t size);



More information about the tor-commits mailing list