]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Fix bug not detecting out of memory condition in _dbus_poll_events ()
authorRalf Habacker <ralf.habacker@freenet.de>
Tue, 28 Apr 2020 05:02:09 +0000 (07:02 +0200)
committerSimon McVittie <smcv@collabora.com>
Wed, 29 Apr 2020 10:52:22 +0000 (10:52 +0000)
For cleaning purpose the event list members are initialized with
WSA_INVALID_EVENT. The cleanup code detects and handles the
case that the event list has been created from calloc ().

dbus/dbus-sysdeps-win.c

index 4c813af3a682315a36679e83b1b1c7af22620e88..2a1a86ea3870031138806f18c0516c22962a460c 100644 (file)
@@ -1186,6 +1186,16 @@ _dbus_poll_events (DBusPollFD *fds,
   else
     pEvents = eventsOnStack;
 
+  if (pEvents == NULL)
+   {
+     _dbus_win_set_errno (ENOMEM);
+     ret = -1;
+     goto oom;
+   }
+
+  for (i = 0; i < n_fds; i++)
+    pEvents[i] = WSA_INVALID_EVENT;
+
   for (i = 0; i < n_fds; i++)
     {
       DBusPollFD *fdp = &fds[i];
@@ -1251,14 +1261,18 @@ _dbus_poll_events (DBusPollFD *fds,
       ret = -1;
     }
 
-  for(i = 0; i < n_fds; i++)
+oom:
+  if (pEvents != NULL)
     {
-      WSACloseEvent (pEvents[i]);
+      for (i = 0; i < n_fds; i++)
+        {
+          if (pEvents[i] != WSA_INVALID_EVENT)
+            WSACloseEvent (pEvents[i]);
+        }
+      if (n_fds > DBUS_STACK_WSAEVENTS)
+        free (pEvents);
     }
 
-  if (n_fds > DBUS_STACK_WSAEVENTS)
-    free (pEvents);
-
   return ret;
 }
 #else