From: Erez Zadok Date: Thu, 6 Oct 2005 21:11:54 +0000 (+0000) Subject: * libamu/strutil.c (xstrlcat, xstrlcpy), include/am_utils.h X-Git-Tag: am-utils-6_2a1~23 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=2b92b18a8d7122216eb13ffe1e39cc8a15cf5879;p=am-utils-6.1.git * 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) --- diff --git a/ChangeLog b/ChangeLog index 2361ad5..7b3e25b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2005-10-06 Erez Zadok + * 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. diff --git a/include/am_utils.h b/include/am_utils.h index 4367852..4d745a8 100644 --- a/include/am_utils.h +++ b/include/am_utils.h @@ -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); diff --git a/libamu/strutil.c b/libamu/strutil.c index 8688a83..2405f15 100644 --- a/libamu/strutil.c +++ b/libamu/strutil.c @@ -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 */ } }