@@ -246,14 +246,12 @@ value_error_int(const char *mesg)
246
246
return -1 ;
247
247
}
248
248
249
- #ifdef CONFIG_32
250
249
static PyObject *
251
250
value_error_ptr (const char * mesg )
252
251
{
253
252
PyErr_SetString (PyExc_ValueError , mesg );
254
253
return NULL ;
255
254
}
256
- #endif
257
255
258
256
static int
259
257
type_error_int (const char * mesg )
@@ -540,6 +538,8 @@ getround(PyObject *v)
540
538
initialized to new SignalDicts. Once a SignalDict is tied to
541
539
a context, it cannot be deleted. */
542
540
541
+ static const char * INVALID_SIGNALDICT_ERROR_MSG = "invalid signal dict" ;
542
+
543
543
static int
544
544
signaldict_init (PyObject * self , PyObject * args UNUSED , PyObject * kwds UNUSED )
545
545
{
@@ -548,22 +548,31 @@ signaldict_init(PyObject *self, PyObject *args UNUSED, PyObject *kwds UNUSED)
548
548
}
549
549
550
550
static Py_ssize_t
551
- signaldict_len (PyObject * self UNUSED )
551
+ signaldict_len (PyObject * self )
552
552
{
553
+ if (SdFlagAddr (self ) == NULL ) {
554
+ return value_error_int (INVALID_SIGNALDICT_ERROR_MSG );
555
+ }
553
556
return SIGNAL_MAP_LEN ;
554
557
}
555
558
556
559
static PyObject * SignalTuple ;
557
560
static PyObject *
558
561
signaldict_iter (PyObject * self UNUSED )
559
562
{
563
+ if (SdFlagAddr (self ) == NULL ) {
564
+ return value_error_ptr (INVALID_SIGNALDICT_ERROR_MSG );
565
+ }
560
566
return PyTuple_Type .tp_iter (SignalTuple );
561
567
}
562
568
563
569
static PyObject *
564
570
signaldict_getitem (PyObject * self , PyObject * key )
565
571
{
566
572
uint32_t flag ;
573
+ if (SdFlagAddr (self ) == NULL ) {
574
+ return value_error_ptr (INVALID_SIGNALDICT_ERROR_MSG );
575
+ }
567
576
568
577
flag = exception_as_flag (key );
569
578
if (flag & DEC_ERRORS ) {
@@ -579,6 +588,10 @@ signaldict_setitem(PyObject *self, PyObject *key, PyObject *value)
579
588
uint32_t flag ;
580
589
int x ;
581
590
591
+ if (SdFlagAddr (self ) == NULL ) {
592
+ return value_error_int (INVALID_SIGNALDICT_ERROR_MSG );
593
+ }
594
+
582
595
if (value == NULL ) {
583
596
return value_error_int ("signal keys cannot be deleted" );
584
597
}
@@ -611,6 +624,10 @@ signaldict_repr(PyObject *self)
611
624
const char * b [SIGNAL_MAP_LEN ]; /* bool */
612
625
int i ;
613
626
627
+ if (SdFlagAddr (self ) == NULL ) {
628
+ return value_error_ptr (INVALID_SIGNALDICT_ERROR_MSG );
629
+ }
630
+
614
631
assert (SIGNAL_MAP_LEN == 9 );
615
632
616
633
for (cm = signal_map , i = 0 ; cm -> name != NULL ; cm ++ , i ++ ) {
@@ -632,6 +649,9 @@ signaldict_richcompare(PyObject *v, PyObject *w, int op)
632
649
PyObject * res = Py_NotImplemented ;
633
650
634
651
assert (PyDecSignalDict_Check (v ));
652
+ if ((SdFlagAddr (v ) == NULL ) || (SdFlagAddr (w ) == NULL )) {
653
+ return value_error_ptr (INVALID_SIGNALDICT_ERROR_MSG );
654
+ }
635
655
636
656
if (op == Py_EQ || op == Py_NE ) {
637
657
if (PyDecSignalDict_Check (w )) {
@@ -660,6 +680,9 @@ signaldict_richcompare(PyObject *v, PyObject *w, int op)
660
680
static PyObject *
661
681
signaldict_copy (PyObject * self , PyObject * args UNUSED )
662
682
{
683
+ if (SdFlagAddr (self ) == NULL ) {
684
+ return value_error_ptr (INVALID_SIGNALDICT_ERROR_MSG );
685
+ }
663
686
return flags_as_dict (SdFlags (self ));
664
687
}
665
688
0 commit comments