X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=smtp.c;h=d831249243192b401831e4ce1ed7f93a0ce0f560;hb=33cddbff323efcbae1503e91e6e65b2733da80c7;hp=062df2b751723182244c9f91553c6a7add2f2b5a;hpb=3e0432c01c37e7cd4f059be7dfd1a1ca2286683b;p=~andy%2Ffetchmail diff --git a/smtp.c b/smtp.c index 062df2b7..d8312492 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++)