[Python-checkins] CVS: python/dist/src/Python sysmodule.c,2.95,2.96
Jeremy Hylton
jhylton@users.sourceforge.net
Wed, 28 Nov 2001 13:44:55 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv29617/Python
Modified Files:
sysmodule.c
Log Message:
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.
Index: sysmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/sysmodule.c,v
retrieving revision 2.95
retrieving revision 2.96
diff -C2 -d -r2.95 -r2.96
*** sysmodule.c 2001/11/09 20:59:39 2.95
--- sysmodule.c 2001/11/28 21:44:53 2.96
***************
*** 1024,1032 ****
else {
char buffer[1001];
! if (vsprintf(buffer, format, va) >= sizeof(buffer))
! Py_FatalError("PySys_WriteStdout/err: buffer overrun");
if (PyFile_WriteString(buffer, file) != 0) {
PyErr_Clear();
fputs(buffer, fp);
}
}
--- 1024,1039 ----
else {
char buffer[1001];
! 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);
+ }
}
}