Newline in subject with system error strings

Issue #70 resolved
Former user created an issue

When monit receives a system error regarding sockets (e.g. "Resource temporarily unavailable"), this text is pasted in the error description and also the mail message, including the subject.

The error string itself comes from strerror() and contains a newline at the end. monit does not handle this, leading to the subject lin ending with two newlines. This messes up the email message as two newlines declare the end of the header.

There should be a routine that checks that whatever is placed in the subject does not contain newlines.

Comments (5)

  1. Tildeslash repo owner

    Could you attach the email message in question? Strerror should not return strings with new-line in them.

  2. bwurst

    The message I get was mangeled by my mail server, so there are header lines after the subject. But here's an example. E-Mail-Messages without system message strings (e.g. process not running) are fine.

    Received: from river (localhost [::ffff:127.0.0.1])
      by river.liioo.com with SMTP; Tue, 22 Jul 2014 00:03:24 +0200
      id 000000000002033F.0000000053CD8E2C.000054DC 
    From: root@schokokeks.org
    To: adminmail-monit@schokokeks.org
    Subject: [monit] river: failed protocol test [HTTP] at INET[xxxxxxxxxxxxxxxxxx:80] via TCP -- HTTP: Error receiving data -- Resource temporarily unavailable
    Message-ID: <courier.0000000053CD8E3A.000058C2@zucker.schokokeks.org>
    Date: Tue, 22 Jul 2014 00:03:38 +0200
    
    Date: Mon, 21 Jul 2014 22:03:23 GMT
    X-Mailer: monit 5.5
    MIME-Version: 1.0
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: 8bit
    Message-Id: <1405980204.1796666135@river>
    
    Connection failed Service apache2 
    
        Date:        Tue, 22 Jul 2014 00:03:23
        Action:      alert
        Host:        river
        Description: failed protocol test [HTTP] at INET[xxxxxxxxxxx:80] via TCP -- HTTP: Error receiving data -- Resource temporarily unavailable
    
    
    Your faithful employee,
    Monit
    
  3. Tildeslash repo owner

    Is there any mail-format customization in your monit configuration file? ("set mail-format" statement).

    The default subject format is: "monit alert -- $EVENT $SERVICE", which doesn't match the format used in your message snip and the new line may come from the customized format.

    We have modified the code to strip any CR/LF characters from the subject, you can get the development snapshot here: https://bitbucket.org/tildeslash/monit/get/master.tar.gz

    To compile:

    tar -xzf master.tar.gz
    cd tildeslash*
    ./bootstrap
    ./configure
    make
    
  4. bwurst

    This is my mail format:

    set mail-format { 
      from: root@schokokeks.org
      subject: [monit] $HOST: $DESCRIPTION }
    

    Thank you for the dev snapshot, I'll try it!

  5. Log in to comment