dryang / rpms / systemd

Forked from rpms/systemd a year ago
Clone
Blob Blame History Raw
From 394185c013c15e47ffa1bdc5948ac6010c329728 Mon Sep 17 00:00:00 2001
From: Michal Schmidt <mschmidt@redhat.com>
Date: Fri, 20 Feb 2015 02:25:16 +0100
Subject: [PATCH] shared: handle unnamed sockets in socket_address_equal()

Make sure we don't inspect sun_path of unnamed sockets.
Since we cannot know if two unnamed sockets' adresses refer to the same
socket, just return false.

(cherry picked from commit 710708a54ccc48e168ad7d4cd401645ef9e2eb14)
---
 src/shared/socket-util.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
index deecce8a8..a4e26b1d8 100644
--- a/src/shared/socket-util.c
+++ b/src/shared/socket-util.c
@@ -349,6 +349,10 @@ bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) {
                 break;
 
         case AF_UNIX:
+                if (a->size <= offsetof(struct sockaddr_un, sun_path) ||
+                    b->size <= offsetof(struct sockaddr_un, sun_path))
+                        return false;
+
                 if ((a->sockaddr.un.sun_path[0] == 0) != (b->sockaddr.un.sun_path[0] == 0))
                         return false;