aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunil Shetye <sunilshetye@rocketmail.com>2011-05-02 00:35:00 +0530
committerMatthias Andree <matthias.andree@gmx.de>2011-05-03 11:37:18 +0200
commit81242009035395b10cca2a23a7ba7e85cc6d3d76 (patch)
tree5f912c98abdede679be874318fcaf03ba3068ca8
parent72ce8bce8dd655b6aefa33d0a74e883dad5202b5 (diff)
downloadfetchmail-81242009035395b10cca2a23a7ba7e85cc6d3d76.tar.gz
fetchmail-81242009035395b10cca2a23a7ba7e85cc6d3d76.tar.bz2
fetchmail-81242009035395b10cca2a23a7ba7e85cc6d3d76.zip
Call strlen() only once when removing CRLF from a line
-rw-r--r--NEWS3
-rw-r--r--smtp.c16
-rw-r--r--transact.c10
3 files changed, 17 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index 221bfcfb..b226dfd5 100644
--- a/NEWS
+++ b/NEWS
@@ -65,6 +65,9 @@ fetchmail-6.3.20 (not yet released):
variants are too diverse, and we've been bitten before -- and configure
complains noisily on Cyrus-SASL's RFC1321 md5.h.
+# BUG FIXES
+* Call strlen() only once when removing CRLF from a line. (Sunil Shetye)
+
# TRANSLATION UPDATES
[ja] Japanese (Takeshi Hamasaki)
diff --git a/smtp.c b/smtp.c
index 611bad07..1c99c696 100644
--- a/smtp.c
+++ b/smtp.c
@@ -185,15 +185,16 @@ int SMTP_ehlo(int sock, char smtp_mode, const char *host, char *name, char *pass
*opt = 0;
while ((SockRead(sock, smtp_response, sizeof(smtp_response)-1)) != -1)
{
- int n = strlen(smtp_response);
+ size_t n;
set_timeout(0);
(void)set_signal_handler(SIGALRM, alrmsave);
- if (smtp_response[strlen(smtp_response)-1] == '\n')
- smtp_response[strlen(smtp_response)-1] = '\0';
- if (smtp_response[strlen(smtp_response)-1] == '\r')
- smtp_response[strlen(smtp_response)-1] = '\0';
+ n = strlen(smtp_response);
+ if (n > 0 && smtp_response[n-1] == '\n')
+ smtp_response[--n] = '\0';
+ if (n > 0 && smtp_response[n-1] == '\r')
+ smtp_response[--n] = '\0';
if (n < 4)
return SM_ERROR;
smtp_response[n] = '\0';
@@ -329,10 +330,9 @@ int SMTP_ok(int sock, char smtp_mode, int mintimeout)
n = strlen(reply);
if (n > 0 && reply[n-1] == '\n')
- n--;
+ reply[--n] = '\0';
if (n > 0 && reply[n-1] == '\r')
- n--;
- reply[n] = '\0';
+ reply[--n] = '\0';
/* stomp over control characters */
for (i = reply; *i; i++)
diff --git a/transact.c b/transact.c
index 55d25168..758e5aaf 100644
--- a/transact.c
+++ b/transact.c
@@ -1554,6 +1554,7 @@ int gen_recv(int sock /** socket to which server is connected */,
char *buf /* buffer to receive input */,
int size /* length of buffer */)
{
+ size_t n;
int oldphase = phase; /* we don't have to be re-entrant */
phase = SERVER_WAIT;
@@ -1573,10 +1574,11 @@ int gen_recv(int sock /** socket to which server is connected */,
else
{
set_timeout(0);
- if (buf[strlen(buf)-1] == '\n')
- buf[strlen(buf)-1] = '\0';
- if (buf[strlen(buf)-1] == '\r')
- buf[strlen(buf)-1] = '\0';
+ n = strlen(buf);
+ if (n > 0 && buf[n-1] == '\n')
+ buf[--n] = '\0';
+ if (n > 0 && buf[n-1] == '\r')
+ buf[--n] = '\0';
if (outlevel >= O_MONITOR)
report(stdout, "%s< %s\n", protocol->name, buf);
phase = oldphase;