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.
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);
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);
* 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 */
}
* 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 */
}
}