Skip to content

Commit 23734b9

Browse files
committed
fix(udl): Fix listener segfault for modules using new listener api
The new UDL Python API defines modrdn as int instead of the string "1": (gdb) p *var $1 = {ob_refcnt = 1000010831, ob_type = 0x7f341f835ae0 <PyLong_Type>} In UCS 5.0 this was not a problem, as `PyArg_Parse(var, "s", &str1);` worked nevertheless and resulted in: (gdb) p str1 $2 = 0x7ffef407aea8 "\002" This seems to have changed in Python 3.11 or earlier and caused: kernel: [18330.428271] univention-dire[15235]: segfault at 0 ip 00007f23ced86618 sp 00007fff7570ae48 error 4 in libc.so.6[7f23cec45000+155000] likely on CPU 0 (core 0, socket 0) kernel: [18330.428285] Code: e1 ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 89 f8 62 a1 fd 00 ef c0 25 ff 0f 00 00 3d e0 0f 00 00 0f 87 38 01 00 00 <62> f3 7d 20 3f 07 00 c5 fb 93 c0 85 c0 74 59 f3 0f bc c0 c3 0f 1f #1 0x00007f341f0bd7ee in __GI___strdup (s=0x0) at ./string/strdup.c:41 #2 0x000055b0683cfd20 in module_get_string (module=<optimized out>, name=name@entry=0x55b0683dbf65 "modrdn") at ./src/handlers.c:158 #3 0x000055b0683d0580 in handler_import (filename=0x7ffc300a2440 "/usr/lib/univention-directory-listener/system/ldap-cache-baa04df67e7af6bb0769f5cb7e72dba9.py") at ./src/handlers.c:239 #4 0x000055b0683d0d02 in handlers_load_path (path=0x55b069fcc7b0 "/usr/lib/univention-directory-listener/system") at ./src/handlers.c:516 #5 0x000055b0683d14a0 in handlers_load_path (path=0x55b069fcc7b0 "/usr/lib/univention-directory-listener/system") at ./src/handlers.c:629 #6 handlers_load_all_paths () at ./src/handlers.c:535 #7 handlers_init () at ./src/handlers.c:627 #8 0x000055b0683ce530 in main (argc=<optimized out>, argv=<optimized out>) at ./src/main.c:564 The modrdn was now changed into a boolean flag. Prior it was evaluated similar. the pure presence of it (e.g. "0") caused modrdn to be evaluated as true. Bug #56533
1 parent 71cc658 commit 23734b9

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

management/univention-directory-listener/src/handlers.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,32 @@ static PyObject *module_get_object(PyObject *module, char *name) {
139139
}
140140

141141

142+
/* Retrieve bool(name) from Python module. */
143+
static bool module_get_bool(PyObject *module, char *name) {
144+
PyObject *attr;
145+
int result;
146+
attr = module_get_object(module, name);
147+
result = PyObject_IsTrue(attr);
148+
Py_XDECREF(attr);
149+
return result == 1;
150+
}
151+
152+
142153
/* Retrieve string from Python module. */
143154
static char *module_get_string(PyObject *module, char *name) {
144155
PyObject *var;
145156
char *str1, *str2 = NULL;
146157

147158
if ((var = PyObject_GetAttrString(module, name)) == NULL)
148-
goto error0;
149-
PyArg_Parse(var, "s", &str1);
159+
goto error1;
160+
if (!PyUnicode_Check(var))
161+
goto error0;
162+
if (PyArg_Parse(var, "s", &str1) != 1)
163+
goto error0;
150164
str2 = strdup(str1);
151-
Py_XDECREF(var);
152165
error0:
166+
Py_XDECREF(var);
167+
error1:
153168
return str2;
154169
}
155170

@@ -228,11 +243,7 @@ static int handler_import(char *filename) {
228243
}
229244

230245
if (PyObject_HasAttrString(handler->module, "modrdn")) { /* optional */
231-
handler->modrdn = module_get_string(handler->module, "modrdn");
232-
if (handler->modrdn == NULL) {
233-
error_msg = "module_get_string(\"modrdn\")";
234-
goto error;
235-
}
246+
handler->modrdn = module_get_bool(handler->module, "modrdn");
236247
}
237248
PyErr_Clear(); // Silent error when attribute is not set
238249

@@ -333,7 +344,6 @@ static int handler_import(char *filename) {
333344
}
334345
free(handler->filters);
335346
free(handler->description);
336-
free(handler->modrdn);
337347
free(handler->name);
338348
free(handler);
339349
univention_debug(UV_DEBUG_LISTENER, UV_DEBUG_ERROR, "import of filename=%s failed in %s", filename, error_msg ? error_msg : "???");

management/univention-directory-listener/src/handlers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct _Handler {
6666
char *description;
6767
struct filter **filters;
6868
char **attributes;
69-
char *modrdn;
69+
bool modrdn;
7070
bool handle_every_delete;
7171
PyObject *handler;
7272
PyObject *initialize;

0 commit comments

Comments
 (0)