[systemd-commits] src/socket.c src/socket-util.c src/socket-util.h

Lennart Poettering lennart at kemper.freedesktop.org
Fri Jun 4 15:53:18 PDT 2010


 src/socket-util.c |    4 +++-
 src/socket-util.h |    2 +-
 src/socket.c      |    8 ++++----
 3 files changed, 8 insertions(+), 6 deletions(-)

New commits:
commit 27ca8d7a250915b290cf89c195e383a8abab35d5
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat Jun 5 00:52:30 2010 +0200

    socket: verify socket type properly when desrializing

diff --git a/src/socket-util.c b/src/socket-util.c
index 0c9fc9f..4a1b3d8 100644
--- a/src/socket-util.c
+++ b/src/socket-util.c
@@ -443,7 +443,7 @@ bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) {
         return true;
 }
 
-bool socket_address_is(const SocketAddress *a, const char *s) {
+bool socket_address_is(const SocketAddress *a, const char *s, int type) {
         struct SocketAddress b;
 
         assert(a);
@@ -452,6 +452,8 @@ bool socket_address_is(const SocketAddress *a, const char *s) {
         if (socket_address_parse(&b, s) < 0)
                 return false;
 
+        b.type = type;
+
         return socket_address_equal(a, &b);
 }
 
diff --git a/src/socket-util.h b/src/socket-util.h
index 993972c..ffcc868 100644
--- a/src/socket-util.h
+++ b/src/socket-util.h
@@ -72,7 +72,7 @@ int socket_address_listen(
                 mode_t socket_mode,
                 int *ret);
 
-bool socket_address_is(const SocketAddress *a, const char *s);
+bool socket_address_is(const SocketAddress *a, const char *s, int type);
 
 bool socket_address_equal(const SocketAddress *a, const SocketAddress *b);
 
diff --git a/src/socket.c b/src/socket.c
index 9091517..19f1d22 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -1067,7 +1067,7 @@ static int socket_serialize(Unit *u, FILE *f, FDSet *fds) {
                         if ((r = socket_address_print(&p->address, &t)) < 0)
                                 return r;
 
-                        unit_serialize_item_format(u, f, "socket", "%i %s", copy, t);
+                        unit_serialize_item_format(u, f, "socket", "%i %i %s", copy, p->address.type, t);
                         free(t);
                 } else {
                         assert(p->type == SOCKET_FIFO);
@@ -1145,15 +1145,15 @@ static int socket_deserialize_item(Unit *u, const char *key, const char *value,
                 }
 
         } else if (streq(key, "socket")) {
-                int fd, skip = 0;
+                int fd, type, skip = 0;
                 SocketPort *p;
 
-                if (sscanf(value, "%i %n", &fd, &skip) < 1 || fd < 0 || !fdset_contains(fds, fd))
+                if (sscanf(value, "%i %i %n", &fd, &type, &skip) < 2 || fd < 0 || type < 0 || !fdset_contains(fds, fd))
                         log_debug("Failed to parse socket value %s", value);
                 else {
 
                         LIST_FOREACH(port, p, s->ports)
-                                if (socket_address_is(&p->address, value+skip))
+                                if (socket_address_is(&p->address, value+skip, type))
                                         break;
 
                         if (p) {


More information about the systemd-commits mailing list