Hi,

    This changes I did fix a nasty crash when using 'Cc' in the
    header parameter to mail() when not being terminated with
    "\r\n". Despite the win32 sendmail code being buggy as hell,
    I'ld like some feedback of testers (ok, I'm not sure if I
    really want this :-), anyway

    - Markus

-- 
Please always Cc to me when replying to me on the lists.
GnuPG Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
---------------------------------------------------------
"I mean "When in doubt, blame mcrypt" is more often right than wrong :)"
"Always right, never wrong :)"
- Two PHP developers who want to remain unnamed
--- Begin Message ---
mfischer                Tue May 14 09:52:19 2002 EDT

  Modified files:              
    /php4/win32 sendmail.c sendmail.h 
  Log:
  - Fix win32 sendmail bug with Cc: in custom header not terminated with \r\n
  - Fix some obvious errors returned by the module, little cleanup.
  
  
Index: php4/win32/sendmail.c
diff -u php4/win32/sendmail.c:1.24 php4/win32/sendmail.c:1.25
--- php4/win32/sendmail.c:1.24  Thu Dec 20 13:06:13 2001
+++ php4/win32/sendmail.c       Tue May 14 09:52:17 2002
@@ -18,7 +18,7 @@
  *
  */
 
-/* $Id: sendmail.c,v 1.24 2001/12/20 18:06:13 fmk Exp $ */
+/* $Id: sendmail.c,v 1.25 2002/05/14 13:52:17 mfischer Exp $ */
 
 #include "php.h"                               /*php specific */
 #include <stdio.h>
@@ -69,26 +69,27 @@
 /* Error messages */
 static char *ErrorMessages[] =
 {
-       {"Success"},
-       {"Bad arguments from form"},
+       {"Success"}, /* 0 */
+       {"Bad arguments from form"}, /* 1 */
        {"Unable to open temporary mailfile for read"},
        {"Failed to Start Sockets"},
        {"Failed to Resolve Host"},
-       {"Failed to obtain socket handle"},
-       {"Failed to Connect"},
+       {"Failed to obtain socket handle"}, /* 5 */
+       {"Failed to connect to mailserver, verify your \"SMTP\" setting in php.ini"},
        {"Failed to Send"},
        {"Failed to Receive"},
        {"Server Error"},
-       {"Failed to resolve the host IP name"},
+       {"Failed to resolve the host IP name"}, /* 10 */
        {"Out of memory"},
        {"Unknown error"},
        {"Bad Message Contents"},
        {"Bad Message Subject"},
-       {"Bad Message destination"},
+       {"Bad Message destination"}, /* 15 */
        {"Bad Message Return Path"},
        {"Bad Mail Host"},
        {"Bad Message File"},
-       {"PHP Internal error: php.ini sendmail from variable not set!"}
+       {"\"sendmail_from\" NOT set in php.ini"},
+       {"Mailserver rejected our \"sendmail_from\" setting"} /* 20 */
 };
 
 
@@ -126,8 +127,9 @@
 
        if (INI_STR("sendmail_from")){
                RPath = estrdup(INI_STR("sendmail_from"));
-               } else {
-                       return 19;
+               } else {
+                       *error = W32_SM_SENDMAIL_FROM_NOT_SET;
+                       return FAILURE;
        }
 
        /* attempt to connect with mail host */
@@ -178,11 +180,12 @@
 //*******************************************************************/
 char *GetSMErrorText(int index)
 {
-
-       if ((index > MAX_ERROR_INDEX) || (index < MIN_ERROR_INDEX))
-               return (ErrorMessages[UNKNOWN_ERROR]);
-       else
-               return (ErrorMessages[index]);
+
+       if (MIN_ERROR_INDEX <= index && index < MAX_ERROR_INDEX) {
+               return (ErrorMessages[index]);
+       } else {
+               return (ErrorMessages[UNKNOWN_ERROR]);
+       }
 }
 
 
@@ -235,7 +238,7 @@
        if ((res = Post(Buffer)) != SUCCESS)
                return (res);
        if ((res = Ack()) != SUCCESS)
-               return (res);
+               return W32_SM_SENDMAIL_FROM_MALFORMED;
 
 
        tempMailTo = estrdup(mailTo);
@@ -255,8 +258,11 @@
        /* Send mail to all Cc rcpt's */
        efree(tempMailTo);
        if (headers && (pos1 = strstr(headers, "Cc:"))) {
-               pos2 = strstr(pos1, "\r\n");
-               tempMailTo = estrndup(pos1, pos2-pos1);
+               if (NULL == (pos2 = strstr(pos1, "\r\n"))) {
+                       tempMailTo = estrndup(pos1, strlen(pos1));
+               } else {
+                       tempMailTo = estrndup(pos1, pos2-pos1);
+               }
 
                token = strtok(tempMailTo, ",");
                while(token != NULL)
Index: php4/win32/sendmail.h
diff -u php4/win32/sendmail.h:1.3 php4/win32/sendmail.h:1.4
--- php4/win32/sendmail.h:1.3   Tue Dec  4 13:47:07 2001
+++ php4/win32/sendmail.h       Tue May 14 09:52:18 2002
@@ -4,29 +4,31 @@
 
 #define HOST_NAME_LEN  256
 #define MAX_APPNAME_LENGHT 100
-#define  MAX_ERROR_INDEX               17
-#define  MIN_ERROR_INDEX               0
-#define  MAIL_BUFFER_SIZE              (1024*4)        /* 4k buffer */
+#define MAIL_BUFFER_SIZE               (1024*4)        /* 4k buffer */
 /* Return values */
-#define        SUCCESS 0
-#define        FAILED_TO_PARSE_ARGUMENTS 1
-#define        FAILED_TO_OPEN_MAILFILE 2
-#define        FAILED_TO_START_SOCKETS 3
-#define        FAILED_TO_RESOLVE_HOST 4
-#define        FAILED_TO_OBTAIN_SOCKET_HANDLE 5
-#define        FAILED_TO_CONNECT 6
-#define        FAILED_TO_SEND 7
-#define        FAILED_TO_RECEIVE 8
-#define        SMTP_SERVER_ERROR 9
-#define        FAILED_TO_GET_HOSTNAME 10
-#define        OUT_OF_MEMORY 11
-#define        UNKNOWN_ERROR 12
-#define        BAD_MSG_CONTENTS 13
-#define        BAD_MSG_SUBJECT 14
-#define        BAD_MSG_DESTINATION 15
-#define        BAD_MSG_RPATH 16
-#define        BAD_MAIL_HOST 17
-#define BAD_MSG_FILE 18
+#define MIN_ERROR_INDEX                                        0 /* Always 0 like 
+SUCCESS */
+#define SUCCESS                                                        0
+#define FAILED_TO_PARSE_ARGUMENTS              1
+#define FAILED_TO_OPEN_MAILFILE                        2
+#define FAILED_TO_START_SOCKETS                        3
+#define FAILED_TO_RESOLVE_HOST                 4
+#define FAILED_TO_OBTAIN_SOCKET_HANDLE 5
+#define FAILED_TO_CONNECT                              6
+#define FAILED_TO_SEND                                 7
+#define FAILED_TO_RECEIVE                              8
+#define SMTP_SERVER_ERROR                              9
+#define FAILED_TO_GET_HOSTNAME                 10
+#define OUT_OF_MEMORY                                  11
+#define UNKNOWN_ERROR                                  12
+#define BAD_MSG_CONTENTS                               13
+#define BAD_MSG_SUBJECT                                        14
+#define BAD_MSG_DESTINATION                            15
+#define BAD_MSG_RPATH                                  16
+#define BAD_MAIL_HOST                                  17
+#define BAD_MSG_FILE                                   18
+#define W32_SM_SENDMAIL_FROM_NOT_SET   19
+#define W32_SM_SENDMAIL_FROM_MALFORMED 20
+#define MAX_ERROR_INDEX                                        21 /* Always last 
+error message + 1 */
 
 
 int TSendMail(char *smtpaddr, int *returnerror,



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to