1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #1229: Check the return value of vsnprintf.

This commit is contained in:
winlin 2022-08-08 08:22:02 +08:00
parent 079ac107f0
commit 5ae495ab95
4 changed files with 94 additions and 32 deletions

View file

@ -101,7 +101,7 @@ SrsCplxError* SrsCplxError::create(const char* func, const char* file, int line,
va_list ap;
va_start(ap, fmt);
static char buffer[4096];
vsnprintf(buffer, sizeof(buffer), fmt, ap);
int r0 = vsnprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap);
SrsCplxError* err = new SrsCplxError();
@ -111,7 +111,9 @@ SrsCplxError* SrsCplxError::create(const char* func, const char* file, int line,
err->line = line;
err->code = code;
err->rerrno = rerrno;
err->msg = buffer;
if (r0 > 0 && r0 < sizeof(buffer)) {
err->msg = string(buffer, r0);
}
err->wrapped = NULL;
if (_srs_context) {
err->cid = _srs_context->get_id();
@ -126,7 +128,7 @@ SrsCplxError* SrsCplxError::wrap(const char* func, const char* file, int line, S
va_list ap;
va_start(ap, fmt);
static char buffer[4096];
vsnprintf(buffer, sizeof(buffer), fmt, ap);
int r0 = vsnprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap);
SrsCplxError* err = new SrsCplxError();
@ -138,7 +140,9 @@ SrsCplxError* SrsCplxError::wrap(const char* func, const char* file, int line, S
err->code = v->code;
}
err->rerrno = rerrno;
err->msg = buffer;
if (r0 > 0 && r0 < sizeof(buffer)) {
err->msg = string(buffer, r0);
}
err->wrapped = v;
if (_srs_context) {
err->cid = _srs_context->get_id();