]> git.pld-linux.org Git - packages/cups.git/blob - cups-dos-backport.patch
- some pld.org.pl->pld-linux.org cosmetics
[packages/cups.git] / cups-dos-backport.patch
1 diff -Nur cups-1.1.14.orig/cups/http.c cups-1.1.14/cups/http.c
2 --- cups-1.1.14.orig/cups/http.c        Wed May 21 14:16:24 2003
3 +++ cups-1.1.14/cups/http.c     Wed May 21 14:49:40 2003
4 @@ -27,6 +27,7 @@
5   *                          default HTTP proxy (if any).
6   *   httpCheck()          - Check to see if there is a pending response from
7   *                          the server.
8 + *   httpWait()           - Wait for data available on a connection.
9   *   httpClose()          - Close an HTTP connection...
10   *   httpConnect()        - Connect to a HTTP server.
11   *   httpConnectEncrypt() - Connect to a HTTP server using encryption.
12 @@ -239,6 +240,18 @@
13  int                            /* O - 0 = no data, 1 = data available */
14  httpCheck(http_t *http)                /* I - HTTP connection */
15  {
16 +  return (httpWait(http, 0));
17 +}
18 +
19 +
20 +/*
21 + * 'httpWait()' - Wait for data available on a connection.
22 + */
23 +
24 +int                            /* O - 0 = no data, 1 = data available */
25 +httpWait(http_t *http,         /* I - HTTP connection */
26 +         int    msec)          /* I - Milliseconds to wait */
27 +{
28    fd_set       input;          /* Input set for select() */
29    struct timeval timeout;      /* Timeout */
30  
31 @@ -253,6 +266,14 @@
32    if (http->used)
33      return (1);
34  
35 +#ifdef HAVE_LIBSSL
36 +  if (http->tls)
37 +  {
38 +    if (SSL_pending((SSL *)(http->tls)))
39 +      return (1);
40 +  }
41 +#endif /* HAVE_LIBSSL */
42 +                       
43   /*
44    * Then try doing a select() to poll the socket...
45    */
46 @@ -260,10 +281,15 @@
47    FD_ZERO(&input);
48    FD_SET(http->fd, &input);
49  
50 -  timeout.tv_sec  = 0;
51 -  timeout.tv_usec = 0;
52 +  if (msec >= 0)
53 +  {
54 +    timeout.tv_sec  = msec / 1000;
55 +    timeout.tv_usec = (msec % 1000) * 1000;
56  
57 -  return (select(http->fd + 1, &input, NULL, NULL, &timeout) > 0);
58 +    return (select(http->fd + 1, &input, NULL, NULL, &timeout) > 0);
59 +  }
60 +  else
61 +    return (select(http->fd + 1, &input, NULL, NULL, NULL) > 0);
62  }
63  
64  
65 @@ -1132,8 +1158,10 @@
66  {
67    char buffer[8192];   /* Junk buffer */
68  
69 -
70 -  while (httpRead(http, buffer, sizeof(buffer)) > 0);
71 +  if (http->state != HTTP_WAITING)
72 +  {
73 +    while (httpRead(http, buffer, sizeof(buffer)) > 0);
74 +  }
75  }
76  
77  
78 @@ -1207,6 +1235,9 @@
79      * Buffer small reads for better performance...
80      */
81  
82 +    if (!http->blocking && !httpWait(http, 1000))
83 +      return (0);
84 +
85      if (http->data_remaining > sizeof(http->buffer))
86        bytes = sizeof(http->buffer);
87      else
88 @@ -1239,7 +1270,10 @@
89        return (-1);
90      }
91      else
92 +    {
93 +      http->error = EPIPE;
94        return (0);
95 +    }
96    }
97  
98    if (http->used > 0)
99 @@ -1259,10 +1293,18 @@
100    }
101  #ifdef HAVE_LIBSSL
102    else if (http->tls)
103 +  {
104 +    if (!http->blocking && !httpWait(http, 1000))
105 +      return (0);
106 +
107      bytes = SSL_read((SSL *)(http->tls), buffer, length);
108 +  }
109  #endif /* HAVE_LIBSSL */
110    else
111    {
112 +    if (!http->blocking && !httpWait(http, 1000))
113 +      return (0);
114 +
115      DEBUG_printf(("httpRead: reading %d bytes from socket...\n", length));
116      bytes = recv(http->fd, buffer, length, 0);
117      DEBUG_printf(("httpRead: read %d bytes from socket...\n", bytes));
118 @@ -1276,6 +1318,11 @@
119  #else
120      http->error = errno;
121  #endif /* WIN32 */
122 +  else
123 +  {
124 +    http->error = EPIPE;
125 +    return (0);
126 +  }
127  
128    if (http->data_remaining == 0)
129    {
130 @@ -1437,6 +1484,9 @@
131        * No newline; see if there is more data to be read...
132        */
133  
134 +      if (!http->blocking && !httpWait(http, 1000))
135 +       return (NULL);
136 +
137  #ifdef HAVE_LIBSSL
138        if (http->tls)
139          bytes = SSL_read((SSL *)(http->tls), bufend,
140 @@ -1473,8 +1523,7 @@
141        }
142        else if (bytes == 0)
143        {
144 -        if (http->blocking)
145 -         http->error = EPIPE;
146 +       http->error = EPIPE;
147  
148          return (NULL);
149        }
150 @@ -1768,6 +1817,7 @@
151         case HTTP_POST_RECV :
152         case HTTP_PUT :
153             http->state ++;
154 +       case HTTP_POST_SEND :
155             break;
156  
157         default :
158 diff -Nur cups-1.1.14.orig/cups/http.h cups-1.1.14/cups/http.h
159 --- cups-1.1.14.orig/cups/http.h        Sun Jan 27 22:16:11 2002
160 +++ cups-1.1.14/cups/http.h     Wed May 21 14:50:15 2003
161 @@ -331,6 +331,10 @@
162  extern char            *httpMD5String(const md5_byte_t *, char [33]);
163  
164  
165 +/**** Backported from CUPS 1.1.19 ****/
166 +extern int             httpWait(http_t *http, int msec);
167 +
168 +
169  /*
170   * C++ magic...
171   */
172 diff -Nur cups-1.1.14.orig/cups/ipp.c cups-1.1.14/cups/ipp.c
173 --- cups-1.1.14.orig/cups/ipp.c Tue Feb 12 19:47:11 2002
174 +++ cups-1.1.14/cups/ipp.c      Wed May 21 14:51:45 2003
175 @@ -2009,7 +2009,14 @@
176        if (http->data_remaining == 0)
177        {
178         if (http->data_encoding == HTTP_ENCODE_CHUNKED)
179 -         httpGets(len, sizeof(len), http);
180 +       {
181 +         /*
182 +          * Get the trailing CR LF after the chunk...
183 +          */
184 +
185 +         if (!httpGets(len, sizeof(len), http))
186 +           return (-1);
187 +       }
188  
189         if (http->data_encoding != HTTP_ENCODE_CHUNKED)
190         {
191 diff -Nur cups-1.1.14.orig/scheduler/client.c cups-1.1.14/scheduler/client.c
192 --- cups-1.1.14.orig/scheduler/client.c Wed May 21 14:16:24 2003
193 +++ cups-1.1.14/scheduler/client.c      Wed May 21 15:03:31 2003
194 @@ -80,6 +80,8 @@
195    client_t             *con;   /* New client pointer */
196    unsigned             address;/* Address of client */
197    struct hostent       *host;  /* Host entry for address */
198 +  static time_t                last_dos = 0;
199 +                               /* Time of last DoS attack */
200  
201  
202    LogMessage(L_DEBUG2, "AcceptClient(%08x) %d NumClients = %d",
203 @@ -317,6 +319,14 @@
204  #endif /* HAVE_LIBSSL */
205  
206   /*
207 +  * Update the activity time so that we timeout after 30 seconds rather
208 +  * then the current Timeout setting (300 by default).  This prevents
209 +  * some DoS situations...
210 +  */
211 +
212 +  con->http.activity = time(NULL) - Timeout + 30;
213 +
214 + /*
215    * Close the socket and clear the file from the input set for select()...
216    */
217  
218 @@ -1378,6 +1388,10 @@
219               }
220             }
221           }
222 +         else if (con->http.state == HTTP_POST_RECV)
223 +         {
224 +           return (0);
225 +         }
226           else if (con->http.state != HTTP_POST_SEND)
227           {
228             CloseClient(con);
This page took 0.042331 seconds and 3 git commands to generate.