diff options
author | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2009-11-11 11:41:06 +0000 |
---|---|---|
committer | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2009-11-11 11:41:06 +0000 |
commit | bdb3c585ad77981c01fa06d17090eac21f6cd3c1 (patch) | |
tree | 5fd898856d7a32f6060fddd4a482dc4cbf15378b | |
parent | 560c034e66e63f886d9928cea223f8a9790dd1ec (diff) |
Fix crlf issue in buf_getln, similar to that in smtp_session.c r1.123.
ok gilles@
-rw-r--r-- | usr.sbin/smtpd/client.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/usr.sbin/smtpd/client.c b/usr.sbin/smtpd/client.c index 26f7567c01b..411351a4c44 100644 --- a/usr.sbin/smtpd/client.c +++ b/usr.sbin/smtpd/client.c @@ -1,8 +1,7 @@ -/* $OpenBSD: client.c,v 1.14 2009/11/11 11:25:17 jacekm Exp $ */ +/* $OpenBSD: client.c,v 1.15 2009/11/11 11:41:05 jacekm Exp $ */ /* * Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net> - * Copyright (c) 2002, 2003 Niels Provos <provos@citi.umich.edu> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -1038,24 +1037,21 @@ buf_getln(struct buf_read *r) /* look for terminating newline */ for (i = 0; i < bufsz; i++) - if (buf[i] == '\r' || buf[i] == '\n') + if (buf[i] == '\n') break; if (i == bufsz) return (NULL); /* make a copy of the line */ - if ((line = malloc(i + 1)) == NULL) + if ((line = calloc(i + 1, 1)) == NULL) return (NULL); - memcpy(line, buf, i); - line[i] = '\0'; + memcpy(line, buf, i); - /* drain the buffer */ - if (i < bufsz - 1) { - char fch = buf[i], sch = buf[i + 1]; + /* handle CRLF */ + if (i != 0 && line[i - 1] == '\r') + line[i - 1] = '\0'; - if ((sch == '\r' || sch == '\n') && sch != fch) - i += 1; - } + /* drain the buffer */ memmove(buf, buf + i + 1, bufsz - i - 1); r->wpos -= i + 1; |