1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-14 19:24:43 +03:00

Fix usage of va_list passed as an arg. Use __va_copy before using it

when it exists.
This commit is contained in:
Jim McDonough -
parent b84882a628
commit 85ab07bdc1
4 changed files with 42 additions and 7 deletions

View File

@ -36,12 +36,18 @@ int d_vfprintf(FILE *f, const char *format, va_list ap)
char *p, *p2;
int ret, maxlen, clen;
const char *msgstr;
va_list ap2;
/* do any message translations */
msgstr = lang_msg(format);
if (!msgstr) return -1;
ret = vasprintf(&p, msgstr, ap);
#if defined(HAVE_VA_COPY)
__va_copy(ap2, ap)
#else
ap2 = ap;
#endif
ret = vasprintf(&p, msgstr, ap2);
lang_msg_free(msgstr);

View File

@ -106,7 +106,7 @@
#endif
static size_t dopr(char *buffer, size_t maxlen, const char *format,
va_list args);
va_list args_in);
static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
char *value, int flags, int min, int max);
static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
@ -149,7 +149,7 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
#define MAX(p,q) (((p) >= (q)) ? (p) : (q))
#endif
static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args)
static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
{
char ch;
LLONG value;
@ -161,6 +161,13 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
int flags;
int cflags;
size_t currlen;
va_list args;
#if defined(HAVE_VA_COPY)
__va_copy(args, args_in);
#else
args = args_in;
#endif
state = DP_S_DEFAULT;
currlen = flags = cflags = min = 0;
@ -793,13 +800,23 @@ static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
int vasprintf(char **ptr, const char *format, va_list ap)
{
int ret;
va_list ap2;
#if defined(HAVE_VA_COPY)
__va_copy(ap2, ap);
#else
ap2 = ap;
#endif
ret = vsnprintf(NULL, 0, format, ap);
ret = vsnprintf(NULL, 0, format, ap2);
if (ret <= 0) return ret;
(*ptr) = (char *)malloc(ret+1);
if (!*ptr) return -1;
ret = vsnprintf(*ptr, ret+1, format, ap);
#if defined(HAVE_VA_COPY)
__va_copy(ap2, ap);
#endif
ret = vsnprintf(*ptr, ret+1, format, ap2);
return ret;
}

View File

@ -1815,7 +1815,13 @@ char *smb_xstrdup(const char *s)
int smb_xvasprintf(char **ptr, const char *format, va_list ap)
{
int n;
n = vasprintf(ptr, format, ap);
va_list ap2;
#if defined(HAVE_VA_COPY)
__va_copy(ap2, ap);
#else
ap2 = ap;
#endif
n = vasprintf(ptr, format, ap2);
if (n == -1 || ! *ptr) {
smb_panic("smb_xvasprintf: out of memory");
}

View File

@ -187,7 +187,13 @@ int x_vfprintf(XFILE *f, const char *format, va_list ap)
{
char *p;
int len, ret;
len = vasprintf(&p, format, ap);
va_list ap2;
#if defined(HAVE_VA_COPY)
__va_copy(ap2, ap);
#else
ap2 = ap;
#endif
len = vasprintf(&p, format, ap2);
if (len <= 0) return len;
ret = x_fwrite(p, 1, len, f);
SAFE_FREE(p);