diff options
| author | Sam Varshavchik | 2021-06-15 21:49:11 -0400 |
|---|---|---|
| committer | Sam Varshavchik | 2021-06-15 22:32:51 -0400 |
| commit | 97ed62b17a2616c758d09105b5a14dd1038cff6f (patch) | |
| tree | 284eb9e557d098f7cfb9d7d92b578b4b619bb4f0 | |
| parent | 142f42378608e593eb36ceb33895db99948427aa (diff) | |
| download | courier-libs-97ed62b17a2616c758d09105b5a14dd1038cff6f.tar.bz2 | |
pop3: buffer input by ourselves.
| -rw-r--r-- | imap/ChangeLog | 4 | ||||
| -rw-r--r-- | imap/configure.ac | 2 | ||||
| -rw-r--r-- | imap/pop3login.c | 64 |
3 files changed, 65 insertions, 5 deletions
diff --git a/imap/ChangeLog b/imap/ChangeLog index f361e74..a7e269b 100644 --- a/imap/ChangeLog +++ b/imap/ChangeLog @@ -1,3 +1,7 @@ +2021-06-15 Sam Varshavchik <mrsam@courier-mta.com> + + * pop3login: use unbuffered reads, handle our own buffering. + 2021-05-21 Sam Varshavchik <mrsam@courier-mta.com> * Minor code tweaks, make it compleable with -Wall -Werror. diff --git a/imap/configure.ac b/imap/configure.ac index 24531e9..576ff26 100644 --- a/imap/configure.ac +++ b/imap/configure.ac @@ -4,7 +4,7 @@ dnl dnl Copyright 1998 - 2021 Double Precision, Inc. See COPYING for dnl distribution information. -AC_INIT(courier-imap, 5.1.3, [courier-users@lists.sourceforge.net]) +AC_INIT(courier-imap, 5.1.3.20210615, [courier-users@lists.sourceforge.net]) >confdefs.h # Kill PACKAGE_ macros diff --git a/imap/pop3login.c b/imap/pop3login.c index 4d43a62..05507ed 100644 --- a/imap/pop3login.c +++ b/imap/pop3login.c @@ -48,6 +48,63 @@ static const char *safe_getenv(const char *p) return p; } +static char getline_buf[1024]; +static size_t getline_buf_size=0; +static size_t getline_i=0; + +static int safe_getc() +{ + if (getline_i >= getline_buf_size) + { + int n=read(0, getline_buf, sizeof(getline_buf)); + + if (n < 0) + n=0; + + if (n == 0) + return -1; + + getline_buf_size=n; + getline_i=0; + } + + return (int)(unsigned char)getline_buf[getline_i++]; +} + +static void safe_fflush() +{ + getline_i=getline_buf_size=0; +} + +static char *safe_fgets(char *buf, size_t buf_size) +{ + size_t i; + + for (i=0; i+1 < buf_size; ++i) + { + int ch=safe_getc(); + + if (ch < 0) + { + if (i == 0) + return NULL; + break; + } + + buf[i]=ch; + if (ch == '\n') + { + ++i; + break; + } + } + + if (i < buf_size) + buf[i]=0; + + return buf; +} + static int starttls() { char *argvec[4]; @@ -76,7 +133,7 @@ static int starttls() printf("+OK Begin SSL/TLS negotiation now.\r\n"); fflush(stdout); - fflush(stdin); + safe_fflush(); cinfo.username=MAILUSER; if (couriertls_start(argvec, &cinfo)) @@ -101,7 +158,6 @@ static int starttls() exit(1); } close(pipefd[0]); - fflush(stdin); putenv("POP3_STARTTLS=NO"); putenv("POP3_TLS_REQUIRED=0"); putenv("POP3_TLS=1"); @@ -116,7 +172,7 @@ char buf[BUFSIZ]; printf("+ %s\r\n", s); fflush(stdout); - if (fgets(buf, sizeof(buf), stdin) == 0) return (0); + if (safe_fgets(buf, sizeof(buf)) == 0) return (0); if ((p=strchr(buf, '\n')) == 0) return (0); if (p > buf && p[-1] == '\r') --p; *p=0; @@ -285,7 +341,7 @@ char *q ; fflush(stdout); fflush(stderr); alarm(60); - while (fgets(buf, sizeof(buf), stdin)) + while (safe_fgets(buf, sizeof(buf))) { c=1; for (p=buf; *p; p++) |
