]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
socket-util: reset length argument for second getsockopt call in fd_[gs]et_rcvbuf
authorChristian Göttsche <cgzones@googlemail.com>
Mon, 14 Sep 2020 17:40:42 +0000 (19:40 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 15 Sep 2020 00:35:36 +0000 (09:35 +0900)
In case the first getsockopt() call changes the value.

src/basic/socket-util.c

index a6552b26876af802353ea5935745c286064a88f0..f2e1148e8743999869cc08cdf8e07e63b7970708 100644 (file)
@@ -640,6 +640,7 @@ int fd_set_sndbuf(int fd, size_t n, bool increase) {
 
         /* SO_SNDBUF above may set to the kernel limit, instead of the requested size.
          * So, we need to check the actual buffer size here. */
+        l = sizeof(value);
         r = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, &l);
         if (r >= 0 && l == sizeof(value) && increase ? (size_t) value >= n*2 : (size_t) value == n*2)
                 return 1;
@@ -670,6 +671,7 @@ int fd_set_rcvbuf(int fd, size_t n, bool increase) {
 
         /* SO_RCVBUF above may set to the kernel limit, instead of the requested size.
          * So, we need to check the actual buffer size here. */
+        l = sizeof(value);
         r = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, &l);
         if (r >= 0 && l == sizeof(value) && increase ? (size_t) value >= n*2 : (size_t) value == n*2)
                 return 1;