]> granicus.if.org Git - php/commitdiff
Prevent header injection by limiting each header to a single line.
authorIlia Alshanetsky <iliaa@php.net>
Tue, 6 Dec 2005 03:39:26 +0000 (03:39 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 6 Dec 2005 03:39:26 +0000 (03:39 +0000)
main/SAPI.c

index 230d191373c14ae4923e0b61b618b9de2950a64a..1b78a5bec2b7fcafdc1d03f6c40a412b8beb4da9 100644 (file)
@@ -588,6 +588,19 @@ SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
        while(isspace(header_line[header_line_len-1])) 
                  header_line[--header_line_len]='\0';
        
+       /* new line safety check */
+       {
+               char *s = header_line, *e = header_line + header_line_len, *p;
+               while (s < e && (p = memchr(s, '\n', (e - s)))) {
+                       if (*(p + 1) == ' ' || *(p + 1) == '\t') {
+                               s = p + 1;
+                               continue;
+                       }
+                       efree(header_line);
+                       sapi_module.sapi_error(E_WARNING, "Header may not contain more then a single header, new line detected.");
+                       return FAILURE;
+               }
+       }
 
        sapi_header.header = header_line;
        sapi_header.header_len = header_line_len;