--- /tmp/php-5.0.5/ext/standard/mail.c 2005-07-28 10:48:31.000000000 +0200 +++ php-5.0.5/ext/standard/mail.c 2006-02-14 00:53:48.000000000 +0100 @@ -104,6 +104,35 @@ return; } + /* check for spam attempts with buggy webforms */ + if (strchr(to, '\n') != NULL || strchr(to, '\r') != NULL) { + zend_error(E_WARNING, "Newlines aren't allowed in the To header."); + RETURN_FALSE; + } + + if (strchr(subject, '\n') != NULL || strchr(subject, '\r') != NULL) { + zend_error(E_WARNING, "Newlines aren't allowed in the Subject header."); + RETURN_FALSE; + } + + /* search for to, cc or bcc headers */ + if (headers != NULL) { + if (strncasecmp(headers, "to:", sizeof("to:") - 1) == 0 || strcasestr(headers, "\nto:")) { + zend_error(E_WARNING, "To: headers aren't allowed in the headers parameter."); + RETURN_FALSE; + } + + if (strncasecmp(headers, "cc:", sizeof("cc:") - 1) == 0 || strcasestr(headers, "\ncc:")) { + zend_error(E_WARNING, "CC: headers aren't allowed in the headers parameter."); + RETURN_FALSE; + } + + if (strncasecmp(headers, "bcc:", sizeof("bcc:") - 1) == 0 || strcasestr(headers, "\nbcc:")) { + zend_error(E_WARNING, "BCC: headers aren't allowed in the headers parameter."); + RETURN_FALSE; + } + } + if (to_len > 0) { to_r = estrndup(to, to_len); for (; to_len; to_len--) { @@ -228,6 +257,26 @@ return 0; } #endif + /* add a SERVER_ADMIN and a SERVER_NAME header to the mail */ + /* do this before all other headers, so these won't affect header forging */ + zval **server_vars, **servername, **serveradmin; + + if (zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), + (void **) &server_vars) == SUCCESS && + Z_TYPE_PP(server_vars) == IS_ARRAY) + { + if (zend_hash_find(Z_ARRVAL_PP(server_vars), "SERVER_NAME", + sizeof("SERVER_NAME"), (void **) &servername) == SUCCESS && + Z_TYPE_PP(servername) == IS_STRING && Z_STRLEN_PP(servername) > 0 && + zend_hash_find(Z_ARRVAL_PP(server_vars), "SERVER_ADMIN", + sizeof("SERVER_ADMIN"), (void **) &serveradmin) == SUCCESS && + Z_TYPE_PP(serveradmin) == IS_STRING && Z_STRLEN_PP(serveradmin) > 0) + { + fprintf(sendmail, "X-serveradmin: %s\nX-servername: %s\n", + Z_STRVAL_PP(serveradmin), Z_STRVAL_PP(servername)); + } + } + /* the user headers */ fprintf(sendmail, "To: %s\n", to); fprintf(sendmail, "Subject: %s\n", subject); if (headers != NULL) {