Edit report at https://bugs.php.net/bug.php?id=55336&edit=1
ID: 55336
User updated by: grabli_2005 at mail dot ru
Reported by: grabli_2005 at mail dot ru
Summary: mail() function is not thread safe for Windows
builds
Status: Open
Type: Bug
Package: Network related
Operating System: Windows
PHP Version: 5.4.0alpha2
Block user comment: N
Private report: N
New Comment:
Yep, I`ve got buffer corruption and socket leak under threading.
There no need of TSRM code, socket handle and buffer can be allocated on stack,
it`s not so big (4kb).
Previous Comments:
------------------------------------------------------------------------
[2011-08-22 14:51:22] [email protected]
Have you encountered any issues specific to this finding? I suppose we could
make a new globals, like PW32G for SendMail and stash the variables in there.
------------------------------------------------------------------------
[2011-08-03 18:20:59] grabli_2005 at mail dot ru
switch status to open, see details in previous comment
------------------------------------------------------------------------
[2011-08-01 13:40:27] grabli_2005 at mail dot ru
I`ve provide this patches as reference only, not as product quality code
replacement.
The only difference that I note since 5.3.0 is FormatEmailAddress function,
that omits <> around emails.
You can check my statment:
look at /ext/standard/mail.c function php_mail
Here nix path: sendmail = popen(sendmail_cmd, "w");
Here win32 path: if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, hdr,
subject, to, message, NULL, NULL, NULL TSRMLS_CC) == FAILURE) {
TSendMail located in win32\sendmail.c
here global variables:
#ifndef THREAD_SAFE
char Buffer[MAIL_BUFFER_SIZE];
/* socket related data */
SOCKET sc;
#ifndef NETWARE
WSADATA Data;
struct hostent *adr;
int WinsockStarted;
/* values set by the constructor */
char *AppName;
#endif /* NETWARE */
SOCKADDR_IN sock_in;
char MailHost[HOST_NAME_LEN];
char LocalHost[HOST_NAME_LEN];
#endif
It`s placed under #ifndef THREAD_SAFE, but THREAD_SAFE not defined anywhere
even when compile with ZTS. More often _THREAD_SAFE used around the code.
If you define THREAD_SAFE it`s break sendmail.c compilation, because rest of
code uses this variables without any define switch.
You can simply debug or place debug printf() in TSendMail and see that this
code executed and uses global variables.
win32\time.c have same issue.
------------------------------------------------------------------------
[2011-08-01 12:55:11] [email protected]
Please provide a patch against 5.3 and 5.4.
Also I'm not sure about your statement.
------------------------------------------------------------------------
[2011-08-01 12:02:42] grabli_2005 at mail dot ru
fixed typo in title
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=55336
--
Edit this bug report at https://bugs.php.net/bug.php?id=55336&edit=1