Skip to contentSkip to conversation

chomp to remove '\r' as well

PATCH In review Mads Martin Joergensen 3 participants 7 messages Sep 11, 2006 – Sep 12, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chomp to remove '\r' as well

Hey together,

Anyone object to this behaviour? Just heard on irc someone got bitten by this:

chomp.c 11 Sep 2006 12:34:28 -0000 renamed from chomp.c 20 Feb 2006 05:00:09 -0000 1.4 +1 -1
@@ -38,7 +38,7 @@
 
        i = strlen(str) - 1;
 
-       while(str[i] = '\n') {
+       while(str[i] = '\n' || str[i] = '\r') {
                str[i] = 0;
                i--;
        }
Signature · 4 lines
Mads Martin Joergensen, http://mmj.dk
"Why make things difficult, when it is possible to make them cryptic
 and totally illogical, with just a little bit more effort?"
                                 -- A. P. J.
#1 lore raw
Quoted 8 lines · Mads Martin Joergensen Mads Martin Joergensen

Hey together,

Anyone object to this behaviour? Just heard on irc someone got bitten by this:

chomp.c 11 Sep 2006 12:34:28 -0000 line 44

Quoted 8 lines
chomp.c 11 Sep 2006 12:34:28 -0000 renamed from chomp.c 20 Feb 2006 05:00:09 -0000 1.4 +1 -1
@@ -38,7 +38,7 @@
 
        i = strlen(str) - 1;
 
-       while(str[i] == '\n') {
+       while(str[i] == '\n' || str[i] == '\r') {
                str[i] = 0;
                i--;
        }

As far as I recall, getting anything with \r\n as an EOL pretty much grossly violates the SMTP RFCs, so I'll make two suggestions about this:

1) Limit it *strictly* to a single \r\n, not any random combination of the two characters. You'll drastically reduce your chances of subtle and nasty misbehaviours being introduced when (not if) some software comes along and relies on things obeying the RFCs.

2) Make it a configurable option. Call it 'broken-CRLF-support' or somesuch, because it most assuredly is.

Outlook is one of the primary offenders in this arena, for what it's worth; DJB had -- probably has -- a rant up about it and why qmail does/did not support a similar feature (it's been years since I used qmail, but the combination of the two provided no end of headaches back when I had to deal with them both at my workplace... and, to a one, they were caused by Outlook blatantly violating the protocol specifications.

Signature · 1 line
Joel Aelwyn <[email protected]>
#2 lore raw
In reply to Mads Martin Joergensen
Quoted 27 lines · Joel Aelwyn
Quoted 6 lines

Anyone object to this behaviour? Just heard on irc someone got bitten by this:

chomp.c 11 Sep 2006 12:34:28 -0000 line 44

Quoted 8 lines
chomp.c 11 Sep 2006 12:34:28 -0000 renamed from chomp.c 20 Feb 2006 05:00:09 -0000 1.4 +1 -1
@@ -38,7 +38,7 @@
 
        i = strlen(str) - 1;
 
-       while(str[i] = '\n') {
+       while(str[i] = '\n' || str[i] = '\r') {
                str[i] = 0;
                i--;
        }

As far as I recall, getting anything with \r\n as an EOL pretty much grossly violates the SMTP RFCs, so I'll make two suggestions about this:

1) Limit it *strictly* to a single \r\n, not any random combination of the two characters. You'll drastically reduce your chances of subtle and nasty misbehaviours being introduced when (not if) some software comes along and relies on things obeying the RFCs.

2) Make it a configurable option. Call it 'broken-CRLF-support' or somesuch, because it most assuredly is.

Quoted 7 lines

Outlook is one of the primary offenders in this arena, for what it's worth; DJB had -- probably has -- a rant up about it and why qmail does/did not support a similar feature (it's been years since I used qmail, but the combination of the two provided no end of headaches back when I had to deal with them both at my workplace... and, to a one, they were caused by Outlook blatantly violating the protocol specifications.

Ah, this has nothing to do with the smtp layer. SMTP always have to have \r\n, and that's handled in send.

Problem is that when I for instance read a subscriber from a subscribers file with the old behaviour and match

"[email protected]" with "[email protected]^M", they're different.

Same thing when reading control files.

Signature · 4 lines
Mads Martin Joergensen, http://mmj.dk
"Why make things difficult, when it is possible to make them cryptic
 and totally illogical, with just a little bit more effort?"
                                 -- A. P. J.
#3 lore raw
In reply to Mads Martin Joergensen
Quoted 39 lines · Mads Martin Joergensen Mads Martin Joergensen
Quoted 27 lines · Joel Aelwyn
Quoted 6 lines

Anyone object to this behaviour? Just heard on irc someone got bitten by this:

chomp.c 11 Sep 2006 12:34:28 -0000 line 44

Quoted 8 lines
chomp.c 11 Sep 2006 12:34:28 -0000 renamed from chomp.c 20 Feb 2006 05:00:09 -0000 1.4 +1 -1
@@ -38,7 +38,7 @@
 
        i = strlen(str) - 1;
 
-       while(str[i] == '\n') {
+       while(str[i] == '\n' || str[i] == '\r') {
                str[i] = 0;
                i--;
        }

As far as I recall, getting anything with \r\n as an EOL pretty much grossly violates the SMTP RFCs, so I'll make two suggestions about this:

1) Limit it *strictly* to a single \r\n, not any random combination of the two characters. You'll drastically reduce your chances of subtle and nasty misbehaviours being introduced when (not if) some software comes along and relies on things obeying the RFCs.

2) Make it a configurable option. Call it 'broken-CRLF-support' or somesuch, because it most assuredly is.

Quoted 7 lines

Outlook is one of the primary offenders in this arena, for what it's worth; DJB had -- probably has -- a rant up about it and why qmail does/did not support a similar feature (it's been years since I used qmail, but the combination of the two provided no end of headaches back when I had to deal with them both at my workplace... and, to a one, they were caused by Outlook blatantly violating the protocol specifications.

Ah, this has nothing to do with the smtp layer. SMTP always have to have \r\n, and that's handled in send.

Quoted 6 lines

Problem is that when I for instance read a subscriber from a subscribers file with the old behaviour and match

"[email protected]" with "[email protected]^M", they're different.

Same thing when reading control files.

Ah, ick. But, in that case, being fancy is probably not warranted... anyone who would get bitten by the broader behaviour is already doing something they need to be smacked for. Comments withdrawn, or at least deferred into the 'nice idea, maybe, but then again maybe not' bucket. :)

Signature · 1 line
Joel Aelwyn <[email protected]>
#4 lore raw
In reply to Mads Martin Joergensen
Quoted 1 line · Mads Martin Joergensen

Anyone object to this behaviour?

[snip]

chomp.c 11 Sep 2006 12:34:28 -0000 line 41

Quoted 2 lines
chomp.c 11 Sep 2006 12:34:28 -0000 renamed from chomp.c 20 Feb 2006 05:00:09 -0000 1.4 +1 -1
-       while(str[i] = '\n') {
+       while(str[i] = '\n' || str[i] = '\r') {

Fine by me.

Was the guy using the twisted BSD variant from Apple Computer, which uses \r and not \n?

Morten

Signature · 2 lines
Morten K. Poulsen <[email protected]>
http://www.afdelingp.dk/
#5 lore raw
In reply to Mads Martin Joergensen
Quoted 10 lines · Morten K. Poulsen
Quoted 1 line · Mads Martin Joergensen

Anyone object to this behaviour?

[snip]

chomp.c 11 Sep 2006 12:34:28 -0000 line 41

Quoted 2 lines
chomp.c 11 Sep 2006 12:34:28 -0000 renamed from chomp.c 20 Feb 2006 05:00:09 -0000 1.4 +1 -1
-       while(str[i] = '\n') {
+       while(str[i] = '\n' || str[i] = '\r') {

Fine by me.

Was the guy using the twisted BSD variant from Apple Computer, which uses \r and not \n?

No, his sysadmins based on windows added ^M's. BSD wouldn't even think of such--albeit Apply have touched it :)

Signature · 4 lines
Mads Martin Joergensen, http://mmj.dk
"Why make things difficult, when it is possible to make them cryptic
 and totally illogical, with just a little bit more effort?"
                                 -- A. P. J.
#6 lore raw
In reply to Mads Martin Joergensen
Quoted 6 lines · Mads Martin Joergensen
Quoted 2 lines · Morten K. Poulsen

Was the guy using the twisted BSD variant from Apple Computer, which uses \r and not \n?

No, his sysadmins based on windows added ^M's. BSD wouldn't even think of such--albeit Apply have touched it :)

Hehe, I see. I thought the Macintoshes still used only \r, but they stopped doing that in Mac OS X. Probably a wise decision :)

Morten

--
Morten K. Poulsen <[email protected]>
http://www.afdelingp.dk/