]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libsystemd-network: use recv(..., 0) instead of read(...) (#3317)
authorTom Gundersen <teg@jklm.no>
Sat, 21 May 2016 21:00:32 +0000 (23:00 +0200)
committerEvgeny Vereshchagin <evvers@ya.ru>
Sat, 21 May 2016 21:00:32 +0000 (00:00 +0300)
According to recv(2) these should be the same, but that is not true.
Passing a buffer of length 0 to read is defined to be a noop according
to read(2), but passing a buffer of length 0 to recv will discard the
pending pacet.

We can easily hit this as we allocate our buffer size depending on
the size of the incoming packet (using FIONREAD). As pointed out in
issue #3299 simply sending an empty UDP packet to the DHCP client
port will trigger a busy loop in networkd as we are polling on the
socket but never discarding the empty packet.

This reverts ad5ae47a0d159ea473c9730d7e0298a3e5d31cf6 but fixes the
same issue.

src/libsystemd-network/sd-dhcp-client.c
src/libsystemd-network/sd-dhcp6-client.c

index 123169832ced34e271e98b32b93348d27399179f..ad79c6cc2cbac76f9ffab8a744bb902dcf1d40f4 100644 (file)
@@ -1636,14 +1636,11 @@ static int client_receive_message_udp(
         if (buflen < 0)
                 return buflen;
 
-        if (buflen == 0)
-                buflen = 1;
-
         message = malloc0(buflen);
         if (!message)
                 return -ENOMEM;
 
-        len = read(fd, message, buflen);
+        len = recv(fd, message, buflen, 0);
         if (len < 0) {
                 if (errno == EAGAIN || errno == EINTR)
                         return 0;
index 0c296e39faf05eb0608d0317b2090fb4e9d0be71..05972e01c938ff75ceaf3a681021ccfe83ee7136 100644 (file)
@@ -917,7 +917,7 @@ static int client_receive_message(sd_event_source *s, int fd, uint32_t revents,
         if (!message)
                 return -ENOMEM;
 
-        len = read(fd, message, buflen);
+        len = recv(fd, message, buflen, 0);
         if (len < 0) {
                 if (errno == EAGAIN || errno == EINTR)
                         return 0;