comparison Python/pythonrun.c @ 20969:c1ecafd15560 legacy-trunk

PyOS_getsig(), PyOS_setsig(): The minimal amount of work to avoid the uninitialized memory reads reported in bug #478001. Note that this doesn't address the following larger issues: - Error conditions are not documented for PyOS_*sig() in the C API. - Nothing that actually calls PyOS_*sig() in the core interpreter and extension modules actually /checks/ the return value of the call. Fixing those is left as an exercise for a later day.
author Barry Warsaw <barry@python.org>
date Tue, 13 Nov 2001 23:08:26 +0000
parents b74610c92d8b
children 379fc66f4c96
comparison
equal deleted inserted replaced
20968:f1cfdca73f86 20969:c1ecafd15560
1435 PyOS_sighandler_t 1435 PyOS_sighandler_t
1436 PyOS_getsig(int sig) 1436 PyOS_getsig(int sig)
1437 { 1437 {
1438 #ifdef HAVE_SIGACTION 1438 #ifdef HAVE_SIGACTION
1439 struct sigaction context; 1439 struct sigaction context;
1440 /* Initialize context.sa_handler to SIG_ERR which makes about as
1441 * much sense as anything else. It should get overwritten if
1442 * sigaction actually succeeds and otherwise we avoid an
1443 * uninitialized memory read.
1444 */
1445 context.sa_handler = SIG_ERR;
1440 sigaction(sig, NULL, &context); 1446 sigaction(sig, NULL, &context);
1441 return context.sa_handler; 1447 return context.sa_handler;
1442 #else 1448 #else
1443 PyOS_sighandler_t handler; 1449 PyOS_sighandler_t handler;
1444 handler = signal(sig, SIG_IGN); 1450 handler = signal(sig, SIG_IGN);
1451 PyOS_setsig(int sig, PyOS_sighandler_t handler) 1457 PyOS_setsig(int sig, PyOS_sighandler_t handler)
1452 { 1458 {
1453 #ifdef HAVE_SIGACTION 1459 #ifdef HAVE_SIGACTION
1454 struct sigaction context; 1460 struct sigaction context;
1455 PyOS_sighandler_t oldhandler; 1461 PyOS_sighandler_t oldhandler;
1462 /* Initialize context.sa_handler to SIG_ERR which makes about as
1463 * much sense as anything else. It should get overwritten if
1464 * sigaction actually succeeds and otherwise we avoid an
1465 * uninitialized memory read.
1466 */
1467 context.sa_handler = SIG_ERR;
1456 sigaction(sig, NULL, &context); 1468 sigaction(sig, NULL, &context);
1457 oldhandler = context.sa_handler; 1469 oldhandler = context.sa_handler;
1458 context.sa_handler = handler; 1470 context.sa_handler = handler;
1459 sigaction(sig, &context, NULL); 1471 sigaction(sig, &context, NULL);
1460 return oldhandler; 1472 return oldhandler;