]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: supervisord sd_notify extension: removed assert in favor of an explicit if
authorVasek Sraier <git@vakabus.cz>
Thu, 29 Sep 2022 14:21:10 +0000 (16:21 +0200)
committerVasek Sraier <git@vakabus.cz>
Thu, 29 Sep 2022 14:22:46 +0000 (16:22 +0200)
manager/knot_resolver_manager/kresd_controller/supervisord/plugin/notifymodule.c

index 4d647d5aef1bc52c3bd9dbc0704c478bf3b57905..d56ee7d2a81bdedfea607da3084f1f1ca0106ecc 100644 (file)
@@ -8,7 +8,6 @@
 #include <sys/types.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 #include <errno.h>
 #include <sys/socket.h>
 #include <fcntl.h>
@@ -115,9 +114,13 @@ static PyObject *handle_control_socket_connection_event(PyObject *self,
        pid_t pid = -1;
        while (cmsgp != NULL) {
                if (cmsgp->cmsg_type == SCM_CREDENTIALS) {
-                       assert(cmsgp->cmsg_len ==
-                              CMSG_LEN(sizeof(struct ucred)));
-                       assert(cmsgp->cmsg_level == SOL_SOCKET);
+                   if (
+                       cmsgp->cmsg_len != CMSG_LEN(sizeof(struct ucred)) ||
+                       cmsgp->cmsg_level != SOL_SOCKET
+                   ) {
+                       printf("[notify_socket] invalid cmsg data, ignoring\n");
+                       Py_RETURN_NONE;
+                   }
 
                        struct ucred cred;
                        memcpy(&cred, CMSG_DATA(cmsgp), sizeof(cred));
@@ -170,4 +173,4 @@ PyMODINIT_FUNC PyInit_notify(void)
        }
 
        return m;
-}
\ No newline at end of file
+}