mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-29 23:16:44 +03:00
stdio: fix detection of malformated format strings
the error code returned by vsnprintf was ignored, resulting in printing the string from a previous print. Change-Id: I8506b05d56da55d1357a1234917adf341b46e1db
This commit is contained in:
@@ -429,12 +429,17 @@ signed int vsprintf(char *pString, const char *pFormat, va_list ap)
|
|||||||
signed int vfprintf(FILE *pStream, const char *pFormat, va_list ap)
|
signed int vfprintf(FILE *pStream, const char *pFormat, va_list ap)
|
||||||
{
|
{
|
||||||
char pStr[MAX_STRING_SIZE];
|
char pStr[MAX_STRING_SIZE];
|
||||||
char pError[] = "stdio.c: increase MAX_STRING_SIZE\n\r";
|
|
||||||
|
|
||||||
// Write formatted string in buffer
|
// Write formatted string in buffer
|
||||||
if (vsprintf(pStr, pFormat, ap) >= MAX_STRING_SIZE) {
|
int rc = vsprintf(pStr, pFormat, ap);
|
||||||
|
if (rc < 0) {
|
||||||
fputs(pError, stderr);
|
fputs("format string error in ", stderr);
|
||||||
|
fputs(pFormat, stderr);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
if (rc >= MAX_STRING_SIZE) {
|
||||||
|
fputs("stdio.c: increase MAX_STRING_SIZE\n\r", stderr);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display string
|
// Display string
|
||||||
@@ -454,12 +459,17 @@ signed int vfprintf(FILE *pStream, const char *pFormat, va_list ap)
|
|||||||
signed int vfprintf_sync(FILE *pStream, const char *pFormat, va_list ap)
|
signed int vfprintf_sync(FILE *pStream, const char *pFormat, va_list ap)
|
||||||
{
|
{
|
||||||
char pStr[MAX_STRING_SIZE];
|
char pStr[MAX_STRING_SIZE];
|
||||||
char pError[] = "stdio.c: increase MAX_STRING_SIZE\n\r";
|
|
||||||
|
|
||||||
// Write formatted string in buffer
|
// Write formatted string in buffer
|
||||||
if (vsprintf(pStr, pFormat, ap) >= MAX_STRING_SIZE) {
|
int rc = vsprintf(pStr, pFormat, ap);
|
||||||
|
if (rc < 0) {
|
||||||
fputs_sync(pError, stderr);
|
fputs_sync("format string error in ", stderr);
|
||||||
|
fputs_sync(pFormat, stderr);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
if (rc >= MAX_STRING_SIZE) {
|
||||||
|
fputs_sync("stdio.c: increase MAX_STRING_SIZE\n\r", stderr);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display string
|
// Display string
|
||||||
|
|||||||
Reference in New Issue
Block a user