Commit ae268607 authored by Peter Pentchev's avatar Peter Pentchev

Fix Debian bug #540571 - the v*printf() functions may NOT be invoked

twice with the same varargs list!  Use vasprintf() if available.

Reported by:	Michael Gold <mgold@ncf.ca>
parent 37405e2a
......@@ -46,6 +46,12 @@ Change log for hexer, the multi-view binary editor
and LTERMLIB; the TERMCAP environment variable is actually
defined in some environments, and it is definitely not
a linker library specification!
- fix a case of undefined behavior in tio.c: the v*printf()
routines may NOT be called a second time with the same
varargs list! Add a HAVE_VASPRINTF definition and enable it
on Linux systems; it is also available on modern BSD's, but
the config.bsd file needs a lot of updating anyway.
Reported by: Michael Gold <mgold@ncf.ca> in Debian bug #540571
0.1.4c
- the last version released by Sascha Demetrio <demetrio@cs.uni-sb.de>
......@@ -11,6 +11,7 @@
#define HAVE_ALLOCA 0
#define NEED_ALLOCA_H 0
#define HAVE_STRERROR 0
#define HAVE_VASPRINTF 0
#define USE_STDARG 0
......@@ -11,6 +11,7 @@
#define HAVE_ALLOCA 0
#define NEED_ALLOCA_H 0
#define HAVE_STRERROR 1
#define HAVE_VASPRINTF 0
#define USE_STDARG 1
......@@ -11,6 +11,7 @@
#define HAVE_ALLOCA 1
#define NEED_ALLOCA_H 1
#define HAVE_STRERROR 1
#define HAVE_VASPRINTF 1
#define USE_STDARG 1
......@@ -11,6 +11,7 @@
#define HAVE_ALLOCA 0
#define NEED_ALLOCA_H 0
#define HAVE_STRERROR 1
#define HAVE_VASPRINTF 0
#define USE_STDARG 1
......@@ -11,6 +11,7 @@
#define HAVE_ALLOCA 1
#define NEED_ALLOCA_H 1
#define HAVE_STRERROR 1
#define HAVE_VASPRINTF 0
#define USE_STDARG 0
......@@ -100,6 +100,10 @@
int tio_readwait_timeout = TIO_READWAIT_TIMEOUT;
#if !HAVE_VASPRINTF
static char printfbuf[2048];
#endif
volatile int *tio_interrupt;
static int
......@@ -541,45 +545,6 @@ tio_isprint(x)
}
/* tio_isprint */
#if USE_STDARG
int
nprintf(const char *fmt, ...)
#else
int
nprintf(fmt, va_alist)
const char *fmt;
va_dcl
#endif
/* Returns the number of output characters a call to a printf-like function
* would pruduce.
*/
{
va_list ap;
int length;
#if USE_STDARG
va_start(ap, fmt);
#else
va_start(ap);
#endif
length = vnprintf(fmt, ap);
va_end(ap);
return length;
}
/* nprintf */
int
vnprintf(fmt, ap)
const char *fmt;
va_list ap;
{
static FILE *null = 0;
if (!null) if (!(null = fopen("/dev/null", "w"))) return -1;
return vfprintf(null, fmt, ap);
}
/* vnprintf */
#if USE_STDARG
static void
tio_error_msg(const char *fmt, ...)
......@@ -2086,13 +2051,20 @@ tio_vprintf(fmt, ap)
*/
{
char *s;
int rval, len;
int rval;
len = vnprintf(fmt, ap);
rval = vsprintf(s = (char *)malloc(len + 1), fmt, ap);
s[len] = 0;
#if HAVE_VASPRINTF
rval = vasprintf(&s, fmt, ap);
#else
rval = vsnprintf(printfbuf, sizeof(printfbuf), fmt, ap);
s = printfbuf;
#endif
if (rval == -1)
return rval;
tio_display(s, 0);
#if HAVE_VASPRINTF
free((char *)s);
#endif
return rval;
}
/* tio_vprintf */
......@@ -2129,13 +2101,20 @@ tio_raw_vprintf(fmt, ap)
*/
{
char *s;
int rval, len;
int rval;
len = vnprintf(fmt, ap);
rval = vsprintf(s = (char *)malloc(len + 1), fmt, ap);
s[len] = 0;
#if HAVE_VASPRINTF
rval = vasprintf(&s, fmt, ap);
#else
rval = snprintf(printfbuf, sizeof(printfbuf), fmt, ap);
s = printfbuf;
#endif
if (rval == -1)
return rval;
tio_puts(s);
#if HAVE_VASPRINTF
free((char *)s);
#endif
return rval;
}
/* tio_raw_vprintf */
......
......@@ -121,19 +121,6 @@ void (*error_msg)(const char *, ...);
int
tio_isprint(int x);
int
#if USE_STDARG
nprintf( const char *fmt, ... );
#else
nprintf(const char *fmt, ...);
#endif
int
vnprintf(const char *fmt, va_list ap);
/* Returns the number of output characters a call to a printf-like function
* would pruduce.
*/
int
tio_init(char *program_name);
/* Initialize. This function should be called before any other
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment