Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prevent SIGSEGV when encoding objects that refer to themselves

Also, there were a few places missing checks for yajl_gen_in_error_status

http://github.com/rtyler/py-yajl/issues#issue/18

Signed-off-by: R. Tyler Ballance <tyler@monkeypox.org>
  • Loading branch information...
commit e2504262a0f1d5a3bae07c74c637f7260832343b 1 parent ac4de75
@teepark teepark authored committed
Showing with 10 additions and 0 deletions.
  1. +10 −0 encoder.c
View
10 encoder.c
@@ -196,6 +196,10 @@ static yajl_gen_status ProcessObject(_YajlEncoder *self, PyObject *object)
if (iterator == NULL)
goto exit;
status = yajl_gen_array_open(handle);
+ if (status == yajl_max_depth_exceeded) {
+ Py_XDECREF(iterator);
+ goto exit;
+ }
while ((item = PyIter_Next(iterator))) {
status = ProcessObject(self, item);
Py_XDECREF(item);
@@ -227,6 +231,7 @@ static yajl_gen_status ProcessObject(_YajlEncoder *self, PyObject *object)
Py_ssize_t position = 0;
status = yajl_gen_map_open(handle);
+ if (status == yajl_max_depth_exceeded) goto exit;
while (PyDict_Next(object, &position, &key, &value)) {
PyObject *newKey = key;
@@ -249,7 +254,12 @@ static yajl_gen_status ProcessObject(_YajlEncoder *self, PyObject *object)
}
status = ProcessObject(self, newKey);
+ if (status == yajl_gen_in_error_state) return status;
+ if (status == yajl_max_depth_exceeded) goto exit;
+
status = ProcessObject(self, value);
+ if (status == yajl_gen_in_error_state) return status;
+ if (status == yajl_max_depth_exceeded) goto exit;
}
return yajl_gen_map_close(handle);
}
Please sign in to comment.
Something went wrong with that request. Please try again.