-/* $OpenBSD: delivery_filename.c,v 1.12 2015/01/20 17:37:54 deraadt Exp $ */
+/* $OpenBSD: delivery_filename.c,v 1.13 2015/10/10 11:42:49 jung Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
delivery_filename_open(struct deliver *deliver)
{
struct stat sb;
- size_t len;
+ size_t sz = 0;
+ ssize_t len;
int fd;
FILE *fp;
- char *ln;
+ char *ln = NULL;
char *msg;
int n;
int escape_from;
error("fdopen");
escape_from = 0;
- while ((ln = fgetln(stdin, &len)) != NULL) {
+ while ((len = getline(&ln, &sz, stdin)) != -1) {
if (ln[len - 1] == '\n')
- len--;
- if (len >= 5 && memcmp(ln, "From ", 5) == 0) {
+ ln[len - 1] = '\0';
+ if (strncmp(ln, "From ", 5) == 0) {
if (escape_from == 0)
escape_from = 1;
else
putc('>', fp);
}
- fprintf(fp, "%.*s\n", (int)len, ln);
+ fprintf(fp, "%s\n", ln);
if (ferror(fp))
break;
}
+ free(ln);
if (ferror(stdin))
error2("read error");
putc('\n', fp);
-/* $OpenBSD: delivery_lmtp.c,v 1.7 2015/01/20 17:37:54 deraadt Exp $ */
+/* $OpenBSD: delivery_lmtp.c,v 1.8 2015/10/10 11:42:49 jung Exp $ */
/*
* Copyright (c) 2013 Ashish SHUKLA <ashish.is@lostca.se>
delivery_lmtp_open(struct deliver *deliver)
{
char *buffer;
- char *lbuf;
char lhloname[255];
int s;
FILE *fp;
enum lmtp_state state = LMTP_BANNER;
- size_t len;
+ size_t sz;
+ ssize_t len;
fp = NULL;
case LMTP_DATA:
if (buffer[0] != '3')
errx(1, "DATA rejected: %s\n", buffer);
- lbuf = NULL;
- while ((buffer = fgetln(stdin, &len))) {
- if (buffer[len- 1] == '\n')
+ buffer = NULL;
+ sz = 0;
+ while ((len = getline(&buffer, &sz, stdin)) != -1) {
+ if (buffer[len - 1] == '\n')
buffer[len - 1] = '\0';
- else {
- if ((lbuf = malloc(len + 1)) == NULL)
- err(1, NULL);
- memcpy(lbuf, buffer, len);
- lbuf[len] = '\0';
- buffer = lbuf;
- }
fprintf(fp, "%s%s\r\n",
*buffer == '.' ? "." : "", buffer);
}
- free(lbuf);
+ free(buffer);
fprintf(fp, ".\r\n");
state = LMTP_QUIT;
break;
-/* $OpenBSD: util.c,v 1.118 2015/10/06 06:04:46 gilles Exp $ */
+/* $OpenBSD: util.c,v 1.119 2015/10/10 11:42:49 jung Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
{
struct addrinfo hints, *res = NULL;
FILE *fp;
- char *buf, *lbuf = NULL;
- size_t buflen;
+ char *buf = NULL;
+ size_t bufsz = 0;
+ ssize_t buflen;
int error, ret = 0;
/* First, check if we have MAILNAME_FILE */
if ((fp = fopen(MAILNAME_FILE, "r")) == NULL)
goto nomailname;
- if ((buf = fgetln(fp, &buflen)) == NULL)
+ if ((buflen = getline(&buf, &bufsz, fp)) == -1)
goto end;
- if (buf[buflen-1] == '\n')
+ if (buf[buflen - 1] == '\n')
buf[buflen - 1] = '\0';
- else {
- if ((lbuf = calloc(buflen + 1, 1)) == NULL) {
- log_warn("calloc");
- fatal("exiting");
- }
- memcpy(lbuf, buf, buflen);
- buf = lbuf;
- }
if (strlcpy(hostname, buf, len) >= len)
fprintf(stderr, MAILNAME_FILE " entry too long");
ret = 1;
end:
- free(lbuf);
+ free(buf);
if (res)
freeaddrinfo(res);
if (fp)