|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40083 in the milter SAPI, the function smfi_getsymval always returns blank strings
Submitted: 2007-01-09 20:51 UTC Modified: 2007-01-10 14:11 UTC
From: tuxracer69 at gmail dot com Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 5.2.0 OS: Linux debi 2.6.17-2-k7 #1 SMP Fr
Private report: No CVE-ID: None
 [2007-01-09 20:51 UTC] tuxracer69 at gmail dot com
The milter SAPI seems unable to get the values of the sendmail macros using the smfi_getsymval function.

My steup:
0) I compile PHP with "--with-milter --disable-cli --disable-cgi"
1) I create a script milter1.php (code below)
2) I insert in my /etc/mail/ the two lines below:
3) I start the milter with:
php-milter -D -p /tmp/milter.sock milter1.php
4) I forge a mail to localhot using telnet to port 25
5) I look at the milter logs which shoud display the vaue of the "i" sendmail macro (the sendmail queueid). 

Reproduce code:

function milter_log($msg)
    $GLOBALS['log'] = fopen("/var/log/milter.log", "a");
    fwrite($GLOBALS['log'], date("[H:i:s d.m.Y] p").getmypid()."\t{$msg}\n");

function milter_init() {
    milter_log("-- startup --");

function milter_envfrom($args){
    foreach ($args as $ix => $arg) {
        milter_log("\targs[$ix] = $arg");

Expected result:
After having started the milter:

# php-milter -D -p /tmp/milter.sock milter1.php

I forge a mail:

# telnet localhost 25
Connected to debi.
Escape character is '^]'.
220 debi.local. ESMTP Sendmail 8.13.7/8.13.7/Debian-2; Tue, 9 Jan 2007 21:25:35 +0100; (No UCE/UBE) logging access from: debi(OK)-debi []
helo me
250 debi.local. Hello debi [], pleased to meet you
mail from:
250 2.1.0 Sender ok
221 2.0.0 debi.local. closing connection
Connection closed by foreign host.

I get the queueid from the sendmail logs:
# tail -n 1 /var/log/mail.log
Jan  9 21:25:55 debi sm-mta[14429]: l09KPZRk014429:, size=0, class=0, nrcpts=0, proto=SMTP, daemon=MTA-v4, relay=debi []

And a  would expect a line in the milter logs saying

[21:25:49 09.01.2007] p14426    queueid=l09KPZRk014429

But (see below the logs I get),  I can not get any value for the "i" macro.
I am sure it is set. If I strace -v -f the milter I see the queueid in a read system call.

Actual result:
The third line in the milter logs shows a blank queueid

tail -f /var/log/milter.log
[21:25:26 09.01.2007] p14426    -- startup --
[21:25:26 09.01.2007] p14426    milter_init()
[21:25:49 09.01.2007] p14426    queueid=
[21:25:49 09.01.2007] p14426    milter_envfrom(args[])
[21:25:49 09.01.2007] p14426            args[0] =

I tried to modify my PHP code and call the macro "{i}" but it does not help.

I would say it is a PHP bug and not a sendmail bug; here is my sendmail version anyway:
# sendmail -d0.1
Version 8.13.7

============ SYSTEM IDENTITY (after readcf) ============
      (short domain name) $w = debi
  (canonical domain name) $j = debi.local.
         (subdomain name) $m = local.
              (node name) $k = debi


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-10 03:52 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

The function is a direct wrapper around smfi_getsymval() 
milter function. So the fact it does not return anything can 
be traced directly to milter and not PHP.
 [2007-01-10 11:58 UTC] tuxracer69 at gmail dot com
Hi Iliia,

I confirm it is  bug in PHP and I even provide a fix below ;)
and thus reopen this bug.
In the file  
the last line in the function 
 (i.e. the line
) seems to be always called and thus the function when called in PHP always return NULL.
Although I am not a SAPI expert (nor a C expert BTW) and thus do not understand why it is always called, removing this line and considering each case fixes the bug.

Iliia could you please confirm this?

==== here is an example of code fixing the bug ======

        char *symname, *ret;
        int len;

        /* valid in any callback */
        if (MG(state) == MLFI_NONE) {
                /*php_error(E_WARNING, IS_NONE, get_active_function_name(TSRMLS_C));*/
                RETVAL_STRING("MLFI_NONE", 1);
        } else {
                if (zend_parse_parameters(1 TSRMLS_CC, "s", &symname, &len) == SUCCESS) {
                    if ((ret = smfi_getsymval(MG(ctx), symname)) != NULL) {
                           RETVAL_STRING(ret, 1);
                    } else {
                         RETVAL_STRING("isnull", 1);
                } else {
                RETVAL_STRING("zend_parse_parameters returned FAILURE", 1);

Note that if I just add again the line 
at the bottom of the function above, I will again get a NULL string all the time.
 [2007-01-10 12:04 UTC]
Please try the next snapshot from, it should be fixed there.
(Though I would not recommend using this SAPI, as it's unmaintained for a long time).
 [2007-01-10 14:04 UTC] tuxracer69 at gmail dot com
Hi Tony,

I saw you replaced the string
by the string

in the php_milter.c code.

And I confirm that works *fine* now.
Thank you.

Please, please, please, do not remove the SAPI from the distribution. Leaving it as 'experimental' is OK but removing it would be a drama. With that many spam on the Internet, it is *so* cool to be able to use our favorite programming language to fight spam or manipulate mails!
Please don't force me to use C or Perl to talk to sendmail ;)(Even so there is  huge amount of work done with Perl).

I think the SAPI code is relatively small, so not not complicated to maintain. As so many programs already depend on the sendmail milter API, we can hope they won't change it soon.

We, the user base, will keep reporting the bugs we find to keep this part of the code up to date.

I will also try to publish some tutorials on the Internet to let people know about this SAPI.

Thanks again for your help and the very fast fix.
 [2007-01-10 14:11 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 15 18:01:29 2024 UTC