FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix problems found by Coverity. · pylee/python@4b20ed9 · GitHub

/ python Public
forked from glix/python

Commit 4b20ed9

Browse files
neal.norwitz
committed
Fix problems found by Coverity.
longobject.c: also fix an ssize_t problem <a> could have been NULL, so hoist the size calc to not use <a>. _ssl.c: under fail: self is DECREF'd, but it would have been NULL. _elementtree.c: delete self if there was an error. _csv.c: I'm not sure if lineterminator could have been anything other than a string. However, other string method calls are checked, so check this one too. git-svn-id: http://svn.python.org/projects/python/trunk@45947 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 1cd2417 commit 4b20ed9

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎Modules/_csv.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,8 @@ join_append_lineterminator(WriterObj *self)
11041104
char *terminator;
11051105

11061106
terminator_len = PyString_Size(self->dialect->lineterminator);
1107+
if (terminator_len == -1)
1108+
return 0;
11071109

11081110
/* grow record buffer if necessary */
11091111
if (!join_check_rec_size(self, self->rec_len + terminator_len))

‎Modules/_elementtree.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,10 @@ element_new(PyObject* tag, PyObject* attrib)
327327

328328
if (attrib != Py_None) {
329329

330-
if (element_new_extra(self, attrib) < 0)
330+
if (element_new_extra(self, attrib) < 0) {
331+
PyObject_Del(self);
331332
return NULL;
333+
}
332334

333335
self->extra->length = 0;
334336
self->extra->allocated = STATIC_CHILDREN;

‎Modules/_ssl.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ newPySSLObject(PySocketSockObject *Sock, char *key_file, char *cert_file)
183183
int sockstate;
184184

185185
self = PyObject_New(PySSLObject, &PySSL_Type); /* Create new object */
186-
if (self == NULL){
187-
errstr = "newPySSLObject error";
188-
goto fail;
186+
if (self == NULL) {
187+
PyErr_SetString(PySSLErrorObject, "newPySSLObject error");
188+
return NULL;
189189
}
190190
memset(self->server, '\0', sizeof(char) * X509_NAME_MAXLEN);
191191
memset(self->issuer, '\0', sizeof(char) * X509_NAME_MAXLEN);

‎Objects/longobject.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ long_normalize(register PyLongObject *v)
6666
PyLongObject *
6767
_PyLong_New(Py_ssize_t size)
6868
{
69-
if (size > INT_MAX) {
70-
/* XXX: Fix this check when ob_size becomes ssize_t */
69+
if (size > PY_SSIZE_T_MAX) {
7170
PyErr_NoMemory();
7271
return NULL;
7372
}
@@ -1580,9 +1579,10 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem)
15801579
assert(size_w == ABS(w->ob_size)); /* That's how d was calculated */
15811580

15821581
size_v = ABS(v->ob_size);
1583-
a = _PyLong_New(size_v - size_w + 1);
1582+
k = size_v - size_w;
1583+
a = _PyLong_New(k + 1);
15841584

1585-
for (j = size_v, k = a->ob_size-1; a != NULL && k >= 0; --j, --k) {
1585+
for (j = size_v; a != NULL && k >= 0; --j, --k) {
15861586
digit vj = (j >= size_v) ? 0 : v->ob_digit[j];
15871587
twodigits q;
15881588
stwodigits carry = 0;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL