]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: refuse to set too large value for socket buffer size
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 8 Sep 2020 15:07:50 +0000 (00:07 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 8 Sep 2020 21:39:05 +0000 (06:39 +0900)
src/basic/socket-util.c

index fb1265985786c711daee7008b2293eed2ea95bb6..3230d76b02be7d2146b0483f47e9e038edf134d8 100644 (file)
@@ -621,6 +621,9 @@ int fd_inc_sndbuf(int fd, size_t n) {
         int r, value;
         socklen_t l = sizeof(value);
 
+        if (n > INT_MAX)
+                return -ERANGE;
+
         r = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, &l);
         if (r >= 0 && l == sizeof(value) && (size_t) value >= n*2)
                 return 0;
@@ -640,6 +643,9 @@ int fd_inc_rcvbuf(int fd, size_t n) {
         int r, value;
         socklen_t l = sizeof(value);
 
+        if (n > INT_MAX)
+                return -ERANGE;
+
         r = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, &l);
         if (r >= 0 && l == sizeof(value) && (size_t) value >= n*2)
                 return 0;