From e7db088dadd801c12b28172cac28541f03fdc557 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 14 Mar 2017 16:46:06 +0000 Subject: Use a macro for the initial length of the buffer instead of 127; OK deraadt@ --- lib/libc/stdio/asprintf.c | 8 +++++--- lib/libc/stdio/vasprintf.c | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/asprintf.c b/lib/libc/stdio/asprintf.c index 48236775908..175765b196d 100644 --- a/lib/libc/stdio/asprintf.c +++ b/lib/libc/stdio/asprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asprintf.c,v 1.22 2015/12/28 22:08:18 mmcc Exp $ */ +/* $OpenBSD: asprintf.c,v 1.23 2017/03/14 16:46:05 millert Exp $ */ /* * Copyright (c) 1997 Todd C. Miller @@ -23,6 +23,8 @@ #include #include "local.h" +#define INITIAL_LEN 127 /* plus one for the NUL */ + int asprintf(char **str, const char *fmt, ...) { @@ -35,10 +37,10 @@ asprintf(char **str, const char *fmt, ...) _FILEEXT_SETUP(&f, &fext); f._file = -1; f._flags = __SWR | __SSTR | __SALC; - f._bf._base = f._p = malloc(128); + f._bf._base = f._p = malloc(INITIAL_LEN + 1); if (f._bf._base == NULL) goto err; - f._bf._size = f._w = 127; /* Leave room for the NUL */ + f._bf._size = f._w = INITIAL_LEN; va_start(ap, fmt); ret = __vfprintf(&f, fmt, ap); va_end(ap); diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c index 98cdb45549f..a5d08509963 100644 --- a/lib/libc/stdio/vasprintf.c +++ b/lib/libc/stdio/vasprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vasprintf.c,v 1.19 2015/12/28 22:08:18 mmcc Exp $ */ +/* $OpenBSD: vasprintf.c,v 1.20 2017/03/14 16:46:05 millert Exp $ */ /* * Copyright (c) 1997 Todd C. Miller @@ -22,6 +22,8 @@ #include #include "local.h" +#define INITIAL_LEN 127 /* plus one for the NUL */ + int vasprintf(char **str, const char *fmt, __va_list ap) { @@ -33,10 +35,10 @@ vasprintf(char **str, const char *fmt, __va_list ap) _FILEEXT_SETUP(&f, &fext); f._file = -1; f._flags = __SWR | __SSTR | __SALC; - f._bf._base = f._p = malloc(128); + f._bf._base = f._p = malloc(INITIAL_LEN + 1); if (f._bf._base == NULL) goto err; - f._bf._size = f._w = 127; /* Leave room for the NUL */ + f._bf._size = f._w = INITIAL_LEN; ret = __vfprintf(&f, fmt, ap); if (ret == -1) goto err; -- cgit v1.2.3