From 1aa06209a155f453f55686f48e420432ff62892c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 20 May 2002 08:04:02 +0000 Subject: When converting from a dictionary to a Samba structure, check for any additional keys that may have been added and return False if so. (This used to be commit 96ccb2beb1d45f8122ff03fc2f7727bf065adbf6) --- source3/python/py_conv.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'source3/python/py_conv.c') diff --git a/source3/python/py_conv.c b/source3/python/py_conv.c index c6f39515af..9093b54b00 100644 --- a/source3/python/py_conv.c +++ b/source3/python/py_conv.c @@ -80,15 +80,19 @@ PyObject *from_struct(void *s, struct pyconv *conv) BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv) { + PyObject *visited, *key, *value; + BOOL result = False; int i; + visited = PyDict_New(); + for (i = 0; conv[i].name; i++) { PyObject *obj; obj = PyDict_GetItemString(dict, conv[i].name); if (!obj) - return False; + goto done; switch (conv[i].type) { case PY_UNISTR: { @@ -125,7 +129,31 @@ BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv) default: break; } + + /* Mark as visited */ + + PyDict_SetItemString(visited, conv[i].name, + PyInt_FromLong(1)); } - return True; + /* Iterate over each item in the input dictionary and see if it was + visited. If it wasn't then the user has added some extra crap + to the dictionary. */ + + i = 0; + + while (PyDict_Next(dict, &i, &key, &value)) { + if (!PyDict_GetItem(visited, key)) + goto done; + } + + result = True; + +done: + /* We must decrement the reference count here or the visited + dictionary will not be freed. */ + + Py_DECREF(visited); + + return result; } -- cgit