OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
Re: [patch] report actual message size in smtpd message

From: Wietse Venema (wietseporcupine.org)
Date: Wed Jul 26 2006 - 08:06:01 CDT


Michael Tokarev:
[ Charset ISO-8859-1 unsupported, converting... ]
> The following patch (attached) changes smtpd to always
> report actual message size if it exceed the limit (as
> checked either by cleanup or by smtpd itself).
> Currently postfix goes by this:
>
> 552 5.3.4 Error: message file too big
>
> With the change, it acts like this (example):
>
> 552 5.3.4 Error: message file too big (12914086 bytes)
>
> The patch changes state->act_size calculation to be
> pefrormed always, regardless of error conditions
> (adding length of the current line to state->act_size).
> One possible issue with this is that when someone will
> try to send huge amount of data, state->act_size may
> overflow, but the only possible consequence is the
> misleading error message. Ofcourse it's possible to
> check for overflow and in case it's found, print
> something like "(>xxx bytes)", but I don't think
> it's worth the trouble.

I would like to maintain higher standards. This also means fixing
my own code, so that it does not overflow before doing the message
size check:

(len is the length of the last read line, and var_message_limit
the per-message size limit).

if (state->err == CLEANUP_STAT_OK) {
    state->act_size += len + 2;
    if (var_message_limit > 0 && state->act_size > var_message_limit)
        state->err = CLEANUP_STAT_SIZE;
    else if (out_record(out_stream, curr_rec_type, start, len) < 0)
        state->err = out_error;

Should be:

if (state->err == CLEANUP_STAT_OK) {
    if (var_message_limit > 0 && var_message_limit - state->act_size < len + 2)
        state->err = CLEANUP_STAT_SIZE;
    else {
        state->act_size += len + 2;
        if (out_record(out_stream, curr_rec_type, start, len) < 0)
            state->err = out_error;
    }

BTW this fix may look weird, but it's done this way so that it will
be correct even when someone changes act_size and var_message_limit
from signed types into unsigned types.

        Wietse