Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit afeb2a4

Browse files
committed
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.
1 parent 79b5b5b commit afeb2a4

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Python/pythonrun.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,12 @@ PyOS_getsig(int sig)
14371437
{
14381438
#ifdef HAVE_SIGACTION
14391439
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;
14401446
sigaction(sig, NULL, &context);
14411447
return context.sa_handler;
14421448
#else
@@ -1453,6 +1459,12 @@ PyOS_setsig(int sig, PyOS_sighandler_t handler)
14531459
#ifdef HAVE_SIGACTION
14541460
struct sigaction context;
14551461
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;
14561468
sigaction(sig, NULL, &context);
14571469
oldhandler = context.sa_handler;
14581470
context.sa_handler = handler;

0 commit comments

Comments
 (0)