[nasal] remediate segfault in lib.c
state of vaCopy is altered during each usage, so it needs to be discarded and not reused by multiple calls.
This commit is contained in:
parent
3d841a214c
commit
3b3093c72e
@ -302,23 +302,28 @@ static naRef f_die(naContext c, naRef me, int argc, naRef* args)
|
|||||||
static char* dosprintf(char* f, ...)
|
static char* dosprintf(char* f, ...)
|
||||||
{
|
{
|
||||||
char* buf;
|
char* buf;
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
int len = 0;
|
|
||||||
va_start(va, f);
|
va_start(va, f);
|
||||||
va_list vaCopy;
|
|
||||||
va_copy(vaCopy, va);
|
int len = vsnprintf(0, 0, f, va);
|
||||||
len = vsnprintf(0, 0, f, vaCopy);
|
va_end(va);
|
||||||
|
|
||||||
if (len <= 0) {
|
if (len <= 0) {
|
||||||
buf = naAlloc(2);
|
buf = (char *) naAlloc(2);
|
||||||
*buf = 0;
|
*buf = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
len++;// allow for terminating null
|
len++;// allow for terminating null
|
||||||
buf = naAlloc(len);
|
buf = (char *) naAlloc(len);
|
||||||
len = vsnprintf(buf, len, f, vaCopy);
|
|
||||||
}
|
va_list va;
|
||||||
|
va_start(va, f);
|
||||||
|
|
||||||
|
len = vsnprintf(buf, len, f, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
va_end(vaCopy);
|
}
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user