diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-11-28 21:44:53 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-11-28 21:44:53 (GMT) |
commit | 5d3d134d560d24a9e6b9d65dd814542605c0b152 (patch) | |
tree | 2b0cb3e0c51937958e414d6814b9764838faf412 /Python/sysmodule.c | |
parent | 4b4ab20f2c07a0e555c0b982089448b5471f6521 (diff) | |
download | cpython-5d3d134d560d24a9e6b9d65dd814542605c0b152.zip cpython-5d3d134d560d24a9e6b9d65dd814542605c0b152.tar.gz cpython-5d3d134d560d24a9e6b9d65dd814542605c0b152.tar.bz2 |
Use PyOS_vsnprintf() and check its return value.
If it returns -1 (which indicates overflow on old Linux platforms and
perhaps on Windows) or size greater than buffer, write a message
indicating that the previous message was truncated.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 1ca69b4..8b27b37 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1023,12 +1023,19 @@ mywrite(char *name, FILE *fp, const char *format, va_list va) vfprintf(fp, format, va); else { char buffer[1001]; - if (vsprintf(buffer, format, va) >= sizeof(buffer)) - Py_FatalError("PySys_WriteStdout/err: buffer overrun"); + int written = PyOS_vsnprintf(buffer, sizeof(buffer), + format, va); if (PyFile_WriteString(buffer, file) != 0) { PyErr_Clear(); fputs(buffer, fp); } + if (written == -1 || written > sizeof(buffer)) { + const char *truncated = "... truncated"; + if (PyFile_WriteString(truncated, file) != 0) { + PyErr_Clear(); + fputs(truncated, fp); + } + } } PyErr_Restore(error_type, error_value, error_traceback); } |