diff options
author | Tim Potter <tpot@samba.org> | 2002-05-20 08:04:02 +0000 |
---|---|---|
committer | Tim Potter <tpot@samba.org> | 2002-05-20 08:04:02 +0000 |
commit | 1aa06209a155f453f55686f48e420432ff62892c (patch) | |
tree | 61d0768488e308bfad3e901c670ab134973a4f04 | |
parent | d62adde88a47f944bc938ac35b153d283b0a74d7 (diff) | |
download | samba-1aa06209a155f453f55686f48e420432ff62892c.tar.gz samba-1aa06209a155f453f55686f48e420432ff62892c.tar.bz2 samba-1aa06209a155f453f55686f48e420432ff62892c.zip |
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)
-rw-r--r-- | source3/python/py_conv.c | 32 |
1 files changed, 30 insertions, 2 deletions
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; } |