Index: contact.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/contact.module,v
retrieving revision 1.41
diff -u -r1.41 contact.module
--- contact.module	10 Feb 2006 05:25:57 -0000	1.41
+++ contact.module	21 Feb 2006 10:28:12 -0000
@@ -157,6 +157,13 @@
   }
 }
 
+function contact_mail_user_validate($form_id, &$form) {
+  global $form_values;
+  if ($form_values['subject'] != str_replace(array("\r", "\n"), '', $form_values['subject'])) {
+    form_set_error('subject', t('The subject cannot contain linebreaks.'));
+  }
+}
+
 function contact_mail_user_submit($form_id, $edit) {
   global $user;
 
@@ -392,6 +399,13 @@
 
 function contact_mail_page_validate($form_id, &$form) {
   global $form_values;
+  if (!valid_email_address($form_values['mail'])) {
+    form_set_error('mail', t('You must enter a valid e-mail address.'));
+  }
+  if ($form_values['subject'] != str_replace(array("\r", "\n"), '', $form_values['subject'])) {
+    form_set_error('subject', t('The subject cannot contain linebreaks.'));
+    watchdog('mail', 'Email injection exploit attempted in contact form subject: ' . check_plain($edit['subject']), WATCHDOG_NOTICE);
+  }
   if (!$form['cid']) {
     // Look if there is only one category
     $result = db_query('SELECT cid FROM {contact}');
@@ -402,10 +416,6 @@
     else {
       form_set_error('category', t('You must select a valid category.'));
     }
-
-    if (!valid_email_address($form['mail'])) {
-      form_set_error('mail', t('You must enter a valid e-mail address.'));
-    }
   }
 }
 
