diff options
| author | Brett Cannon <bcannon@gmail.com> | 2008-06-27 00:31:13 (GMT) | 
|---|---|---|
| committer | Brett Cannon <bcannon@gmail.com> | 2008-06-27 00:31:13 (GMT) | 
| commit | dea1b5653ffd2183c7a4d577a2ca08644dd51248 (patch) | |
| tree | dc441e1ddb4884a57e4fc305fa77f87b7a100578 /Python/_warnings.c | |
| parent | 80821f7cf4b2af64e444ad71ca13eb96fcbd6454 (diff) | |
| download | cpython-dea1b5653ffd2183c7a4d577a2ca08644dd51248.zip cpython-dea1b5653ffd2183c7a4d577a2ca08644dd51248.tar.gz cpython-dea1b5653ffd2183c7a4d577a2ca08644dd51248.tar.bz2  | |
warnings.warn_explicit() did not have the proper TypeErrors in place to prevent
bus errors or SystemError being raised. As a side effect of fixing this, a bad
DECREF that could be triggered when 'message' and 'category' were both None was
fixed.
Closes issue 3211. Thanks JP Calderone for the bug report.
Diffstat (limited to 'Python/_warnings.c')
| -rw-r--r-- | Python/_warnings.c | 18 | 
1 files changed, 13 insertions, 5 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c index e3daf77..07b98ef 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -280,6 +280,11 @@ warn_explicit(PyObject *category, PyObject *message,      PyObject *item = Py_None;      const char *action;      int rc; +     +    if (registry && !PyDict_Check(registry) && (registry != Py_None)) { +        PyErr_SetString(PyExc_TypeError, "'registry' must be a dict"); +        return NULL; +    }      /* Normalize module. */      if (module == NULL) { @@ -303,6 +308,8 @@ warn_explicit(PyObject *category, PyObject *message,      else {          text = message;          message = PyObject_CallFunction(category, "O", message); +        if (message == NULL) +            goto cleanup;      }      lineno_obj = PyInt_FromLong(lineno); @@ -314,7 +321,7 @@ warn_explicit(PyObject *category, PyObject *message,      if (key == NULL)          goto cleanup; -    if (registry != NULL) { +    if ((registry != NULL) && (registry != Py_None)) {          rc = already_warned(registry, key, 0);          if (rc == -1)              goto cleanup; @@ -336,12 +343,13 @@ warn_explicit(PyObject *category, PyObject *message,         is "always". */      rc = 0;      if (strcmp(action, "always") != 0) { -        if (registry != NULL && PyDict_SetItem(registry, key, Py_True) < 0) +        if (registry != NULL && registry != Py_None && +                PyDict_SetItem(registry, key, Py_True) < 0)              goto cleanup;          else if (strcmp(action, "ignore") == 0)              goto return_none;          else if (strcmp(action, "once") == 0) { -            if (registry == NULL) { +            if (registry == NULL || registry == Py_None) {                  registry = get_once_registry();                  if (registry == NULL)                      goto cleanup; @@ -351,7 +359,7 @@ warn_explicit(PyObject *category, PyObject *message,          }          else if (strcmp(action, "module") == 0) {              /* registry[(text, category, 0)] = 1 */ -            if (registry != NULL) +            if (registry != NULL && registry != Py_None)                  rc = update_registry(registry, text, category, 0);          }          else if (strcmp(action, "default") != 0) { @@ -435,7 +443,7 @@ warn_explicit(PyObject *category, PyObject *message,      Py_XDECREF(text);      Py_XDECREF(lineno_obj);      Py_DECREF(module); -    Py_DECREF(message); +    Py_XDECREF(message);      return result;  /* Py_None or NULL. */  }  | 
