aboutsummaryrefslogtreecommitdiffstats
path: root/main/cups/cups-check-sockaddr-size.patch
blob: ce966dc97085668113201ddb45fe4ca005afc6f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
diff --git a/backend/lpd.c b/backend/lpd.c
index 6e4ab36..bbffb82 100644
--- a/backend/lpd.c
+++ b/backend/lpd.c
@@ -1244,6 +1244,7 @@ rresvport_af(int *port,			/* IO - Port number to bind to */
 {
   http_addr_t	addr;			/* Socket address */
   int		fd;			/* Socket file descriptor */
+  socklen_t	socksz=sizeof(struct sockaddr);	/* size of struct sockaddr* */
 
 
  /*
@@ -1260,6 +1261,23 @@ rresvport_af(int *port,			/* IO - Port number to bind to */
   memset(&addr, 0, sizeof(addr));
   addr.addr.sa_family = family;
 
+  switch(family) {
+    case AF_INET:
+      socksz = sizeof(struct sockaddr_in);
+      break;
+#ifdef AF_INET6
+    case AF_INET6:
+      socksz = sizeof(struct sockaddr_in6);
+      break;
+#endif
+#ifdef AF_LOCAL
+    case AF_LOCAL:
+      socksz = sizeof(struct sockaddr_un);
+#endif
+    default:
+      break;
+  }
+
  /*
   * Try to bind the socket to a reserved port...
   */
@@ -1276,7 +1294,7 @@ rresvport_af(int *port,			/* IO - Port number to bind to */
     * Try binding the port to the socket; return if all is OK...
     */
 
-    if (!bind(fd, (struct sockaddr *)&addr, sizeof(addr)))
+    if (!bind(fd, (struct sockaddr *)&addr, socksz))
       return (fd);
 
    /*