Rev 1425: Check return values of Py_BuildValue. in http://people.samba.org/bzr/jelmer/bzr-svn/trunk
Jelmer Vernooij
jelmer at samba.org
Thu Jul 3 17:38:32 BST 2008
At http://people.samba.org/bzr/jelmer/bzr-svn/trunk
------------------------------------------------------------
revno: 1425
revision-id: jelmer at samba.org-20080703163827-oq661a51d56qp5d6
parent: jelmer at samba.org-20080702002510-vthyzwxslw3ayahw
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Thu 2008-07-03 18:38:27 +0200
message:
Check return values of Py_BuildValue.
modified:
client.c client.pyx-20080313235339-wbyjbw2namuiql8f-1
ra.c ra.pyx-20080313140933-qybkqaxe3m4mcll7-1
util.c util.c-20080531154025-s8ef6ej9tytsnkkw-1
wc.c wc.pyx-20080313142018-10l8l23vha2j9e6b-1
=== modified file 'client.c'
--- a/client.c 2008-07-01 23:36:39 +0000
+++ b/client.c 2008-07-03 16:38:27 +0000
@@ -89,17 +89,26 @@
APR_ARRAY_IDX(commit_items, i, svn_client_commit_item2_t *);
PyObject *item, *copyfrom;
- if (commit_item->copyfrom_url != NULL)
+ if (commit_item->copyfrom_url != NULL) {
copyfrom = Py_BuildValue("(si)", commit_item->copyfrom_url,
commit_item->copyfrom_rev);
- else
+ if (copyfrom == NULL) {
+ PyObject_Del(ret);
+ return NULL;
+ }
+ } else {
copyfrom = Py_None;
+ }
item = Py_BuildValue("(szlNi)",
/* commit_item->path */ "foo",
commit_item->url, commit_item->revision,
copyfrom,
commit_item->state_flags);
+ if (item == NULL) {
+ PyObject_Del(ret);
+ return NULL;
+ }
if (PyList_SetItem(ret, i, item) != 0)
return NULL;
=== modified file 'ra.c'
--- a/ra.c 2008-07-01 23:36:39 +0000
+++ b/ra.c 2008-07-03 16:38:27 +0000
@@ -414,17 +414,26 @@
if (ops == NULL)
return NULL;
for (i = 0; i < window->num_ops; i++) {
- PyList_SetItem(ops, i, Py_BuildValue("(iII)", window->ops[i].action_code,
- window->ops[i].offset,
- window->ops[i].length));
+ PyObject *pyval = Py_BuildValue("(iII)",
+ window->ops[i].action_code,
+ window->ops[i].offset,
+ window->ops[i].length);
+ if (pyval == NULL)
+ return NULL;
+ PyList_SetItem(ops, i, pyval);
}
if (window->new_data != NULL && window->new_data->data != NULL) {
py_new_data = PyString_FromStringAndSize(window->new_data->data, window->new_data->len);
} else {
py_new_data = Py_None;
}
- py_window = Py_BuildValue("((LIIiOO))", window->sview_offset, window->sview_len, window->tview_len,
- window->src_ops, ops, py_new_data);
+ py_window = Py_BuildValue("((LIIiOO))",
+ window->sview_offset,
+ window->sview_len,
+ window->tview_len,
+ window->src_ops, ops, py_new_data);
+ if (py_window == NULL)
+ return NULL;
Py_DECREF(ops);
Py_DECREF(py_new_data);
}
@@ -1484,8 +1493,14 @@
ret = PyDict_New();
for (idx = apr_hash_first(temp_pool, hash_locks); idx != NULL;
idx = apr_hash_next(idx)) {
+ PyObject *pyval;
apr_hash_this(idx, (const void **)&key, &klen, (void **)&lock);
- PyDict_SetItemString(ret, key, pyify_lock(lock));
+ pyval = pyify_lock(lock);
+ if (pyval == NULL) {
+ apr_pool_destroy(temp_pool);
+ return NULL;
+ }
+ PyDict_SetItemString(ret, key, pyval);
}
apr_pool_destroy(temp_pool);
@@ -2160,6 +2175,9 @@
cert_info->issuer_dname, cert_info->ascii_cert);
}
+ if (py_cert == NULL)
+ return py_svn_error();
+
ret = PyObject_CallFunction(fn, "slOb", realm, failures, py_cert, may_save);
Py_DECREF(py_cert);
if (ret == NULL)
=== modified file 'util.c'
--- a/util.c 2008-06-29 22:06:49 +0000
+++ b/util.c 2008-07-03 16:38:27 +0000
@@ -61,6 +61,7 @@
void PyErr_SetSubversionException(svn_error_t *error)
{
PyObject *coremod = PyImport_ImportModule("bzrlib.plugins.svn.core"), *excobj;
+ PyObject *excval;
if (coremod == NULL) {
return;
@@ -73,7 +74,8 @@
return;
}
- PyErr_SetObject(excobj, Py_BuildValue("(si)", error->message, error->apr_err));
+ excval = Py_BuildValue("(si)", error->message, error->apr_err);
+ PyErr_SetObject(excobj, excval);
}
bool check_error(svn_error_t *error)
@@ -149,7 +151,7 @@
static PyObject *pyify_changed_paths(apr_hash_t *changed_paths, apr_pool_t *pool)
{
- PyObject *py_changed_paths;
+ PyObject *py_changed_paths, *pyval;
apr_hash_index_t *idx;
const char *key;
apr_ssize_t klen;
@@ -162,9 +164,11 @@
for (idx = apr_hash_first(pool, changed_paths); idx != NULL;
idx = apr_hash_next(idx)) {
apr_hash_this(idx, (const void **)&key, &klen, (void **)&val);
- PyDict_SetItemString(py_changed_paths, key,
- Py_BuildValue("(czi)", val->action, val->copyfrom_path,
- val->copyfrom_rev));
+ pyval = Py_BuildValue("(czi)", val->action, val->copyfrom_path,
+ val->copyfrom_rev);
+ if (pyval == NULL)
+ return NULL;
+ PyDict_SetItemString(py_changed_paths, key, pyval);
}
}
=== modified file 'wc.c'
--- a/wc.c 2008-07-01 23:36:39 +0000
+++ b/wc.c 2008-07-03 16:38:27 +0000
@@ -415,7 +415,7 @@
AdmObject *admobj = (AdmObject *)self;
svn_prop_t el;
int i;
- PyObject *py_propchanges, *py_orig_props;
+ PyObject *py_propchanges, *py_orig_props, *pyval;
if (!PyArg_ParseTuple(args, "s", &path))
return NULL;
@@ -428,11 +428,17 @@
py_propchanges = PyList_New(propchanges->nelts);
for (i = 0; i < propchanges->nelts; i++) {
el = APR_ARRAY_IDX(propchanges, i, svn_prop_t);
- PyList_SetItem(py_propchanges, i,
- Py_BuildValue("(ss#)", el.name, el.value->data, el.value->len));
+ pyval = Py_BuildValue("(ss#)", el.name, el.value->data, el.value->len);
+ if (pyval == NULL) {
+ apr_pool_destroy(temp_pool);
+ return NULL;
+ }
+ PyList_SetItem(py_propchanges, i, pyval);
}
py_orig_props = prop_hash_to_dict(original_props);
apr_pool_destroy(temp_pool);
+ if (py_orig_props == NULL)
+ return NULL;
return Py_BuildValue("(NN)", py_propchanges, py_orig_props);
}
More information about the bazaar-commits
mailing list