mirror of
https://github.com/samba-team/samba.git
synced 2025-03-09 08:58:35 +03:00
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)
This commit is contained in:
parent
d62adde88a
commit
1aa06209a1
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user