From: Erez Zadok Date: Sun, 14 Aug 2005 20:01:13 +0000 (+0000) Subject: * libamu/xutil.c (real_plog, xsnprintf): call new xvsnprintf() X-Git-Tag: before-clocktime-fixes~32 X-Git-Url: https://git.fsl.cs.stonybrook.edu/?a=commitdiff_plain;h=34c667106c87585ea1d14004c5cf32974a20a04f;p=am-utils-6.1.git * libamu/xutil.c (real_plog, xsnprintf): call new xvsnprintf() wrapper function. (xvsnprintf): new function which already gets a va_list. This was needed to avoid nesting va_list's (which apparently isn't allowed). * include/am_utils.h: prototype for new xvsnprintf wrapper. --- diff --git a/ChangeLog b/ChangeLog index 3fbd7f5..1b8d7c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2005-08-14 Erez Zadok + * libamu/xutil.c (real_plog, xsnprintf): call new xvsnprintf() + wrapper function. + (xvsnprintf): new function which already gets a va_list. This was + needed to avoid nesting va_list's (which apparently isn't + allowed). + + * include/am_utils.h: prototype for new xvsnprintf wrapper. + * configure.in: sinclude([vers.m4]) version number file. * vers.m4: new file to separate version number out of diff --git a/include/am_utils.h b/include/am_utils.h index 092cda7..f11e088 100644 --- a/include/am_utils.h +++ b/include/am_utils.h @@ -334,6 +334,7 @@ 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)); diff --git a/libamu/xutil.c b/libamu/xutil.c index b9ce246..bd87a6b 100644 --- a/libamu/xutil.c +++ b/libamu/xutil.c @@ -439,11 +439,11 @@ real_plog(int lvl, const char *fmt, va_list vargs) #endif /* DEBUG_MEM */ /* - * Note: xsnprintf() may call plog() if a truncation happened, but the + * Note: xvsnprintf() may call plog() if a truncation happened, but the * latter has some code to break out of an infinite loop. See comment in * xsnprintf() below. */ - xsnprintf(ptr, 1023, expand_error(fmt, efmt, 1024), vargs); + xvsnprintf(ptr, 1023, expand_error(fmt, efmt, 1024), vargs); ptr += strlen(ptr); if (*(ptr-1) == '\n') @@ -961,25 +961,38 @@ xsnprintf(char *str, size_t size, const char *format, ...) int ret = 0; va_start(ap, format); + ret = xvsnprintf(str, size, format, ap); + va_end(ap); + + return ret; +} + + +/* our version of vsnprintf */ +int +xvsnprintf(char *str, size_t size, const char *format, va_list ap) +{ + int ret = 0; + #ifdef HAVE_VSNPRINTF ret = vsnprintf(str, size, format, ap); #else /* not HAVE_VSNPRINTF */ ret = vsprintf(str, format, ap); /* less secure version */ #endif /* not HAVE_VSNPRINTF */ - va_end(ap); /* * If error or truncation, plog error. * * WARNING: we use the static 'maxtrunc' variable below to break out any - * possible infinite recursion between plog() and xsnprintf(). If it ever - * happens, it'd indicate a bug in Amd. + * possible infinite recursion between plog() and xvsnprintf(). If it + * ever happens, it'd indicate a bug in Amd. */ - if (ret < 0 || (size_t) ret >= size) { /* error or truncation occured */ - static int maxtrunc; /* hack to avoid inifinite loop */ + if (ret < 0 || ret >= size) { /* error or truncation occured */ + static int maxtrunc; /* hack to avoid inifinite loop */ if (++maxtrunc > 10) plog(XLOG_ERROR, "BUG: string %p truncated (ret=%d, format=\"%s\")", - str, ret, format); + str, ret, format); } + return ret; }