Fix pg_dump crashes caused by bogus use of va_start/va_end (only seen
on some platforms, which is not too surprising considering how platform specific these macros must be).
This commit is contained in:
parent
b25e60d887
commit
2b0f8ae009
@ -872,21 +872,21 @@ int archprintf(Archive* AH, const char *fmt, ...)
|
|||||||
int bSize = strlen(fmt) + 256;
|
int bSize = strlen(fmt) + 256;
|
||||||
int cnt = -1;
|
int cnt = -1;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
|
|
||||||
/* This is paranoid: deal with the possibility that vsnprintf is willing to ignore trailing null */
|
/* This is paranoid: deal with the possibility that vsnprintf is willing to ignore trailing null */
|
||||||
/* or returns > 0 even if string does not fit. It may be the case that it returns cnt = bufsize */
|
/* or returns > 0 even if string does not fit. It may be the case that it returns cnt = bufsize */
|
||||||
while (cnt < 0 || cnt >= (bSize-1) ) {
|
while (cnt < 0 || cnt >= (bSize-1) )
|
||||||
if (p != NULL) free(p);
|
|
||||||
bSize *= 2;
|
|
||||||
if ((p = malloc(bSize)) == NULL)
|
|
||||||
{
|
{
|
||||||
va_end(ap);
|
if (p != NULL) free(p);
|
||||||
exit_horribly(AH, "%s: could not allocate buffer for archprintf\n", progname);
|
bSize *= 2;
|
||||||
}
|
p = (char*)malloc(bSize);
|
||||||
cnt = vsnprintf(p, bSize, fmt, ap);
|
if (p == NULL)
|
||||||
|
{
|
||||||
|
exit_horribly(AH, "%s: could not allocate buffer for archprintf\n", progname);
|
||||||
|
}
|
||||||
|
va_start(ap, fmt);
|
||||||
|
cnt = vsnprintf(p, bSize, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
}
|
}
|
||||||
va_end(ap);
|
|
||||||
WriteData(AH, p, cnt);
|
WriteData(AH, p, cnt);
|
||||||
free(p);
|
free(p);
|
||||||
return cnt;
|
return cnt;
|
||||||
@ -977,21 +977,21 @@ int ahprintf(ArchiveHandle* AH, const char *fmt, ...)
|
|||||||
int bSize = strlen(fmt) + 256; /* Should be enough */
|
int bSize = strlen(fmt) + 256; /* Should be enough */
|
||||||
int cnt = -1;
|
int cnt = -1;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
/* This is paranoid: deal with the possibility that vsnprintf is willing to ignore trailing null */
|
/* This is paranoid: deal with the possibility that vsnprintf is willing to ignore trailing null */
|
||||||
/* or returns > 0 even if string does not fit. It may be the case that it returns cnt = bufsize */
|
/* or returns > 0 even if string does not fit. It may be the case that it returns cnt = bufsize */
|
||||||
while (cnt < 0 || cnt >= (bSize - 1) ) {
|
while (cnt < 0 || cnt >= (bSize - 1) )
|
||||||
|
{
|
||||||
if (p != NULL) free(p);
|
if (p != NULL) free(p);
|
||||||
bSize *= 2;
|
bSize *= 2;
|
||||||
p = (char*)malloc(bSize);
|
p = (char*)malloc(bSize);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
{
|
{
|
||||||
va_end(ap);
|
|
||||||
die_horribly(AH, "%s: could not allocate buffer for ahprintf\n", progname);
|
die_horribly(AH, "%s: could not allocate buffer for ahprintf\n", progname);
|
||||||
}
|
}
|
||||||
|
va_start(ap, fmt);
|
||||||
cnt = vsnprintf(p, bSize, fmt, ap);
|
cnt = vsnprintf(p, bSize, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
}
|
}
|
||||||
va_end(ap);
|
|
||||||
ahwrite(p, 1, cnt, AH);
|
ahwrite(p, 1, cnt, AH);
|
||||||
free(p);
|
free(p);
|
||||||
return cnt;
|
return cnt;
|
||||||
|
@ -899,24 +899,22 @@ static int tarPrintf(ArchiveHandle *AH, TAR_MEMBER *th, const char *fmt, ...)
|
|||||||
int bSize = strlen(fmt) + 256; /* Should be enough */
|
int bSize = strlen(fmt) + 256; /* Should be enough */
|
||||||
int cnt = -1;
|
int cnt = -1;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
/* This is paranoid: deal with the possibility that vsnprintf is willing to ignore trailing null */
|
/* This is paranoid: deal with the possibility that vsnprintf is willing to ignore trailing null */
|
||||||
/* or returns > 0 even if string does not fit. It may be the case that it returns cnt = bufsize */
|
/* or returns > 0 even if string does not fit. It may be the case that it returns cnt = bufsize */
|
||||||
while (cnt < 0 || cnt >= (bSize - 1) ) {
|
while (cnt < 0 || cnt >= (bSize - 1) )
|
||||||
|
{
|
||||||
if (p != NULL) free(p);
|
if (p != NULL) free(p);
|
||||||
bSize *= 2;
|
bSize *= 2;
|
||||||
p = (char*)malloc(bSize);
|
p = (char*)malloc(bSize);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
{
|
{
|
||||||
va_end(ap);
|
die_horribly(AH, "%s: could not allocate buffer for tarPrintf\n", progname);
|
||||||
die_horribly(AH, "%s: could not allocate buffer for ahprintf\n", progname);
|
|
||||||
}
|
}
|
||||||
|
va_start(ap, fmt);
|
||||||
cnt = vsnprintf(p, bSize, fmt, ap);
|
cnt = vsnprintf(p, bSize, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
}
|
}
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
cnt = tarWrite(p, cnt, th);
|
cnt = tarWrite(p, cnt, th);
|
||||||
|
|
||||||
free(p);
|
free(p);
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user