Loading ...
Sorry, an error occurred while loading the content.

[patch] report actual message size in smtpd message

Expand Messages
  • Michael Tokarev
    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).
    Message 1 of 6 , Jul 26, 2006
    • 0 Attachment
      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.

      Also, it's possible to output actual message size
      limit on the same message, but since the limits
      may be different for cleanup and smtpd, I don't
      think it's a good idea, especially since smtpd
      already prints out the SIZE=xxx line to the
      EHLO command.

      And around this, I've a question.

      Currently, there are several cases which aren't
      logged by smtpd, including this "message is too
      big" (btw, shouldn't it be "message file IS too
      big", with the "is" part?). Should it log this
      and similar conditions? I think it should, but
      I don't quite sure where to do so, and for which
      conditions, too.

      Thanks.

      /mjt
    • Michael Tokarev
      ... er, wrong patch (reversed). Now resending with the correct one. /mjt
      Message 2 of 6 , Jul 26, 2006
      • 0 Attachment
        Michael Tokarev wrote:
        > 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).

        er, wrong patch (reversed). Now resending with the correct
        one.

        /mjt
      • Wietse Venema
        Michael Tokarev: [ Charset ISO-8859-1 unsupported, converting... ] ... I would like to maintain higher standards. This also means fixing my own code, so that
        Message 3 of 6 , Jul 26, 2006
        • 0 Attachment
          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
        • Michael Tokarev
          ... It can overflow only if var_message_limit is near the maximum for (u)long, so that one more line makes it overflow. I d say it s more than enouth to
          Message 4 of 6 , Jul 26, 2006
          • 0 Attachment
            Wietse Venema wrote:
            > 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:

            It can overflow only if var_message_limit is near the maximum for
            (u)long, so that one more line makes it overflow. I'd say it's
            more than enouth to ensure var_message_limit is below [U]LONG_MAX
            minus some sane number (line_length_limit or whatever) for this to
            never happen at all.

            Yes state->act_size may overflow. But if var_message_limit has
            sane value, we will notice over-sized message BEFORE act_size will
            overflow. And as the result, the only issue left is the mentioned
            above misleading diagnostic message. Which can only happen (on a
            32-bit architecture anyway) with amount of data > 2 gigabytes.


            /mjt
          • Wietse Venema
            ... I would like to avoid reporting message too large -12345 bytes . Wietse
            Message 5 of 6 , Jul 26, 2006
            • 0 Attachment
              Michael Tokarev:
              > Yes state->act_size may overflow. But if var_message_limit has
              > sane value, we will notice over-sized message BEFORE act_size will
              > overflow. And as the result, the only issue left is the mentioned
              > above misleading diagnostic message. Which can only happen (on a
              > 32-bit architecture anyway) with amount of data > 2 gigabytes.

              I would like to avoid reporting "message too large -12345 bytes".

              Wietse
            • Michael Tokarev
              ... Ok, I stand corrected. While in 99,999% of cases not checking for overflow *just* when printing actual size will be ok... Today I received the following
              Message 6 of 6 , Aug 1 5:17 AM
              • 0 Attachment
                Wietse Venema wrote:
                > Michael Tokarev:
                >> Yes state->act_size may overflow. But if var_message_limit has
                >> sane value, we will notice over-sized message BEFORE act_size will
                >> overflow. And as the result, the only issue left is the mentioned
                >> above misleading diagnostic message. Which can only happen (on a
                >> 32-bit architecture anyway) with amount of data > 2 gigabytes.
                >
                > I would like to avoid reporting "message too large -12345 bytes".

                Ok, I stand corrected. While in 99,999% of cases not checking for
                overflow *just* when printing actual size will be ok... Today I
                received the following postmaster-notification from my patched
                Postfix:

                In: MAIL FROM: ...
                Out: 250 2.1.0 Ok
                In: RCPT TO: ...
                Out: 250 2.1.5 Ok
                In: DATA
                Out: 354 End data with <CR><LF>.<CR><LF>
                Out: 552 5.3.4 Error: message file too big (1412594067 bytes)

                So.. umm. Oh well. They're close... (the limit is the
                default, 10M).

                /mjt
              Your message has been successfully submitted and would be delivered to recipients shortly.