* libamu/strutil.c (xstrlcat, xstrlcpy), include/am_utils.h
authorErez Zadok <ezk@cs.sunysb.edu>
Thu, 6 Oct 2005 21:11:54 +0000 (21:11 +0000)
committerErez Zadok <ezk@cs.sunysb.edu>
Thu, 6 Oct 2005 21:11:54 +0000 (21:11 +0000)
(DEBUG): if debugging is on, then also print the source file name
and line number that called xstrl* with a buffer that wasn't large
enough (most likely an am-utils bug)

ChangeLog
include/am_utils.h
libamu/strutil.c

index 2361ad5fcdde021abd06a99634a7dce04b718457..7b3e25be45cc3eda4e4b944df1d73f0b31cc48d3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2005-10-06  Erez Zadok  <ezk@cs.sunysb.edu>
 
+       * libamu/strutil.c (xstrlcat, xstrlcpy), include/am_utils.h
+       (DEBUG): if debugging is on, then also print the source file name
+       and line number that called xstrl* with a buffer that wasn't large
+       enough (most likely an am-utils bug)
+
        * include/am_compat.h (INADDR_NONE): define in a common location,
        if OS doesn't have it, use 0xffffffffU which should work with any
        ANSI compiler.
index 4367852436845a3cc784f1fd78bea0713f1c6092..4d745a8990b778934f415f3e2ce83fc63cf2a598 100644 (file)
@@ -323,8 +323,6 @@ extern void rmdirs(char *);
 extern void rpc_msg_init(struct rpc_msg *, u_long, u_long, u_long);
 extern void set_amd_program_number(u_long program);
 extern void show_opts(int ch, struct opt_tab *);
-extern void xstrlcat(char *dst, const char *src, size_t len);
-extern void xstrlcpy(char *dst, const char *src, size_t len);
 extern void unregister_amq(void);
 extern voidp xmalloc(int);
 extern voidp xrealloc(voidp, int);
@@ -332,11 +330,22 @@ extern voidp xzalloc(int);
 extern int check_pmap_up(char *host, struct sockaddr_in* sin);
 extern u_long get_nfs_version(char *host, struct sockaddr_in *sin, u_long nfs_version, const char *proto);
 extern long get_server_pid(void);
-extern int xsnprintf(char *str, size_t size, const char *format, ...);
-extern int xvsnprintf(char *str, size_t size, const char *format, va_list ap);
 extern void setup_sighandler(int signum, void (*handler)(int));
 extern time_t clocktime(nfstime *nt);
 
+extern int xsnprintf(char *str, size_t size, const char *format, ...);
+extern int xvsnprintf(char *str, size_t size, const char *format, va_list ap);
+
+#ifdef DEBUG
+extern void _xstrlcat(char *dst, const char *src, size_t len, const char *filename, int lineno);
+# define xstrlcat(d,s,l)       _xstrlcat((d),(s),(l),__FILE__,__LINE__)
+extern void _xstrlcpy(char *dst, const char *src, size_t len, const char *filename, int lineno);
+# define xstrlcpy(d,s,l)       _xstrlcpy((d),(s),(l),__FILE__,__LINE__)
+#else /* not DEBUG */
+extern void xstrlcat(char *dst, const char *src, size_t len);
+extern void xstrlcpy(char *dst, const char *src, size_t len);
+#endif /* not DEBUG */
+
 #ifdef MOUNT_TABLE_ON_FILE
 extern void rewrite_mtab(mntlist *, const char *);
 extern void unlock_mntlist(void);
index 8688a8398fcfc33c62ccc35bb03558b5152e08ca..2405f15c3a84a63dd3991a1c1a258cafb8764c0a 100644 (file)
@@ -161,12 +161,21 @@ strsplit(char *s, int ch, int qc)
  * the Amd code do we actually use the return value of strncpy/strlcpy.
  */
 void
+#ifdef DEBUG
+_xstrlcpy(char *dst, const char *src, size_t len, const char *filename, int lineno)
+#else /* not DEBUG */
 xstrlcpy(char *dst, const char *src, size_t len)
+#endif /* not DEBUG */
 {
   if (len == 0)
     return;
   if (strlcpy(dst, src, len) >= len)
+#ifdef DEBUG
+    plog(XLOG_ERROR, "xstrlcpy(%s:%d): string \"%s\" truncated to \"%s\"",
+        filename, lineno, src, dst);
+#else /* not DEBUG */
     plog(XLOG_ERROR, "xstrlcpy: string \"%s\" truncated to \"%s\"", src, dst);
+#endif /* not DEBUG */
 }
 
 
@@ -179,14 +188,23 @@ xstrlcpy(char *dst, const char *src, size_t len)
  * the Amd code do we actually use the return value of strncat/strlcat.
  */
 void
+#ifdef DEBUG
+_xstrlcat(char *dst, const char *src, size_t len, const char *filename, int lineno)
+#else /* not DEBUG */
 xstrlcat(char *dst, const char *src, size_t len)
+#endif /* not DEBUG */
 {
   if (len == 0)
     return;
   if (strlcat(dst, src, len) >= len) {
     /* strlcat does not null terminate if the size of src is equal to len. */
     dst[strlen(dst) - 1] = '\0';
+#ifdef DEBUG
+    plog(XLOG_ERROR, "xstrlcat(%s:%d): string \"%s\" truncated to \"%s\"",
+        filename, lineno, src, dst);
+#else /* not DEBUG */
     plog(XLOG_ERROR, "xstrlcat: string \"%s\" truncated to \"%s\"", src, dst);
+#endif /* not DEBUG */
   }
 }