Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 61716:942b3c168f15
Issue #6697: Check that _PyUnicode_AsString() result is not NULL
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Wed, 19 May 2010 00:34:15 +0000 |
| parents | f3f95ed82744 |
| children | deed5fce82d6 |
comparison
equal
deleted
inserted
replaced
| 61711:7fc48ad16087 | 61716:942b3c168f15 |
|---|---|
| 136 | 136 |
| 137 #if defined(HAVE_LANGINFO_H) && defined(CODESET) | 137 #if defined(HAVE_LANGINFO_H) && defined(CODESET) |
| 138 static char* | 138 static char* |
| 139 get_codeset(void) | 139 get_codeset(void) |
| 140 { | 140 { |
| 141 char* codeset; | 141 char* codeset, *name_str; |
| 142 PyObject *codec, *name; | 142 PyObject *codec, *name = NULL; |
| 143 | 143 |
| 144 codeset = nl_langinfo(CODESET); | 144 codeset = nl_langinfo(CODESET); |
| 145 if (!codeset || codeset[0] == '\0') | 145 if (!codeset || codeset[0] == '\0') |
| 146 return NULL; | 146 return NULL; |
| 147 | 147 |
| 152 name = PyObject_GetAttrString(codec, "name"); | 152 name = PyObject_GetAttrString(codec, "name"); |
| 153 Py_CLEAR(codec); | 153 Py_CLEAR(codec); |
| 154 if (!name) | 154 if (!name) |
| 155 goto error; | 155 goto error; |
| 156 | 156 |
| 157 codeset = strdup(_PyUnicode_AsString(name)); | 157 name_str = _PyUnicode_AsString(name); |
| 158 if (name == NULL) | |
| 159 goto error; | |
| 160 codeset = strdup(name_str); | |
| 158 Py_DECREF(name); | 161 Py_DECREF(name); |
| 159 return codeset; | 162 return codeset; |
| 160 | 163 |
| 161 error: | 164 error: |
| 162 Py_XDECREF(codec); | 165 Py_XDECREF(codec); |
| 166 Py_XDECREF(name); | |
| 163 return NULL; | 167 return NULL; |
| 164 } | 168 } |
| 165 #endif | 169 #endif |
| 166 | 170 |
| 167 void | 171 void |
| 1058 return -1; | 1062 return -1; |
| 1059 oenc = PyObject_GetAttrString(v, "encoding"); | 1063 oenc = PyObject_GetAttrString(v, "encoding"); |
| 1060 if (!oenc) | 1064 if (!oenc) |
| 1061 return -1; | 1065 return -1; |
| 1062 enc = _PyUnicode_AsString(oenc); | 1066 enc = _PyUnicode_AsString(oenc); |
| 1067 if (enc == NULL) | |
| 1068 return -1; | |
| 1063 } | 1069 } |
| 1064 v = PySys_GetObject("ps1"); | 1070 v = PySys_GetObject("ps1"); |
| 1065 if (v != NULL) { | 1071 if (v != NULL) { |
| 1066 v = PyObject_Str(v); | 1072 v = PyObject_Str(v); |
| 1067 if (v == NULL) | 1073 if (v == NULL) |
| 1068 PyErr_Clear(); | 1074 PyErr_Clear(); |
| 1069 else if (PyUnicode_Check(v)) | 1075 else if (PyUnicode_Check(v)) { |
| 1070 ps1 = _PyUnicode_AsString(v); | 1076 ps1 = _PyUnicode_AsString(v); |
| 1077 if (ps1 == NULL) { | |
| 1078 PyErr_Clear(); | |
| 1079 ps1 = ""; | |
| 1080 } | |
| 1081 } | |
| 1071 } | 1082 } |
| 1072 w = PySys_GetObject("ps2"); | 1083 w = PySys_GetObject("ps2"); |
| 1073 if (w != NULL) { | 1084 if (w != NULL) { |
| 1074 w = PyObject_Str(w); | 1085 w = PyObject_Str(w); |
| 1075 if (w == NULL) | 1086 if (w == NULL) |
| 1076 PyErr_Clear(); | 1087 PyErr_Clear(); |
| 1077 else if (PyUnicode_Check(w)) | 1088 else if (PyUnicode_Check(w)) { |
| 1078 ps2 = _PyUnicode_AsString(w); | 1089 ps2 = _PyUnicode_AsString(w); |
| 1090 if (ps2 == NULL) { | |
| 1091 PyErr_Clear(); | |
| 1092 ps2 = ""; | |
| 1093 } | |
| 1094 } | |
| 1079 } | 1095 } |
| 1080 arena = PyArena_New(); | 1096 arena = PyArena_New(); |
| 1081 if (arena == NULL) { | 1097 if (arena == NULL) { |
| 1082 Py_XDECREF(v); | 1098 Py_XDECREF(v); |
| 1083 Py_XDECREF(w); | 1099 Py_XDECREF(w); |
