From f1ada79a83f6ac42f5efd995bf04374005ac532b Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 2 May 2014 17:56:56 -0700 Subject: [PATCH] Sync with current OpenBSD stdio. We'd fallen a little behind. Bug: 14492135 Change-Id: Ic1137ef10bffccecebd5ce51086c23db006d0ea3 --- libc/Android.mk | 1 + libc/upstream-openbsd/lib/libc/stdio/fgetln.c | 4 ++-- libc/upstream-openbsd/lib/libc/stdio/fputws.c | 5 ++--- libc/upstream-openbsd/lib/libc/stdio/fread.c | 16 +++++++++++++++- libc/upstream-openbsd/lib/libc/stdio/vfprintf.c | 9 ++++----- libc/upstream-openbsd/lib/libc/stdio/vfscanf.c | 6 +++--- libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c | 11 ++++------- libc/upstream-openbsd/lib/libc/stdio/vfwscanf.c | 9 ++++----- 8 files changed, 35 insertions(+), 26 deletions(-) diff --git a/libc/Android.mk b/libc/Android.mk index bcf546f55..ff21d6af9 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -673,6 +673,7 @@ LOCAL_CFLAGS := \ $(libc_common_cflags) \ -I$(LOCAL_PATH)/upstream-openbsd/android/include \ -I$(LOCAL_PATH)/upstream-openbsd/lib/libc/include \ + -I$(LOCAL_PATH)/upstream-openbsd/lib/libc/gdtoa/ \ -include openbsd-compat.h LOCAL_CONLYFLAGS := $(libc_common_conlyflags) LOCAL_CPPFLAGS := $(libc_common_cppflags) diff --git a/libc/upstream-openbsd/lib/libc/stdio/fgetln.c b/libc/upstream-openbsd/lib/libc/stdio/fgetln.c index 539b3c081..d0c0809be 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/fgetln.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fgetln.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fgetln.c,v 1.11 2009/11/21 09:53:44 guenther Exp $ */ +/* $OpenBSD: fgetln.c,v 1.12 2013/11/12 07:04:06 deraadt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -43,7 +43,7 @@ * so we add 1 here. #endif */ -int +static int __slbexpand(FILE *fp, size_t newsize) { void *p; diff --git a/libc/upstream-openbsd/lib/libc/stdio/fputws.c b/libc/upstream-openbsd/lib/libc/stdio/fputws.c index c4c2d8ea0..108846e70 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/fputws.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fputws.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fputws.c,v 1.6 2013/04/17 17:40:35 tedu Exp $ */ +/* $OpenBSD: fputws.c,v 1.7 2013/11/12 07:04:35 deraadt Exp $ */ /* $NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $ */ /*- @@ -34,8 +34,7 @@ #include #include #include "local.h" - -wint_t __fputwc_unlock(wchar_t wc, FILE *fp); +#include "fvwrite.h" int fputws(ws, fp) diff --git a/libc/upstream-openbsd/lib/libc/stdio/fread.c b/libc/upstream-openbsd/lib/libc/stdio/fread.c index 430865d02..8a592f6d3 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/fread.c +++ b/libc/upstream-openbsd/lib/libc/stdio/fread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fread.c,v 1.11 2009/11/21 09:53:44 guenther Exp $ */ +/* $OpenBSD: fread.c,v 1.12 2014/05/01 16:40:36 deraadt Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -33,8 +33,12 @@ #include #include +#include +#include #include "local.h" +#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) + size_t fread(void *buf, size_t size, size_t count, FILE *fp) { @@ -43,6 +47,16 @@ fread(void *buf, size_t size, size_t count, FILE *fp) int r; size_t total; + /* + * Extension: Catch integer overflow + */ + if ((size >= MUL_NO_OVERFLOW || count >= MUL_NO_OVERFLOW) && + size > 0 && SIZE_MAX / size < count) { + errno = EOVERFLOW; + fp->_flags |= __SERR; + return (0); + } + /* * ANSI and SUSv2 require a return value of 0 if size or count are 0. */ diff --git a/libc/upstream-openbsd/lib/libc/stdio/vfprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vfprintf.c index b4f8f296c..86b540e92 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/vfprintf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/vfprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfprintf.c,v 1.63 2013/03/02 19:40:08 guenther Exp $ */ +/* $OpenBSD: vfprintf.c,v 1.65 2014/03/19 05:17:01 guenther Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -216,11 +216,10 @@ __wcsconv(wchar_t *wcsarg, int prec) #include #include #include "floatio.h" +#include "gdtoa.h" #define DEFPREC 6 -extern char *__dtoa(double, int, int, int *, int *, char **); -extern void __freedtoa(char *); static int exponent(char *, int, int); #endif /* FLOATING_POINT */ @@ -399,7 +398,7 @@ __vfprintf(FILE *fp, const char *fmt0, __va_list ap) flags&PTRINT ? GETARG(ptrdiff_t) : \ flags&SIZEINT ? GETARG(ssize_t) : \ flags&SHORTINT ? (short)GETARG(int) : \ - flags&CHARINT ? (__signed char)GETARG(int) : \ + flags&CHARINT ? (signed char)GETARG(int) : \ GETARG(int))) #define UARG() \ ((uintmax_t)(flags&MAXINT ? GETARG(uintmax_t) : \ @@ -810,7 +809,7 @@ fp_common: else if (flags & SHORTINT) *GETARG(short *) = ret; else if (flags & CHARINT) - *GETARG(__signed char *) = ret; + *GETARG(signed char *) = ret; else if (flags & PTRINT) *GETARG(ptrdiff_t *) = ret; else if (flags & SIZEINT) diff --git a/libc/upstream-openbsd/lib/libc/stdio/vfscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vfscanf.c index c2996a971..abefe32cb 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/vfscanf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/vfscanf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfscanf.c,v 1.30 2013/04/17 17:40:35 tedu Exp $ */ +/* $OpenBSD: vfscanf.c,v 1.31 2014/03/19 05:17:01 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -273,7 +273,7 @@ literal: if (flags & SUPPRESS) continue; if (flags & SHORTSHORT) - *va_arg(ap, __signed char *) = nread; + *va_arg(ap, signed char *) = nread; else if (flags & SHORT) *va_arg(ap, short *) = nread; else if (flags & LONG) @@ -749,7 +749,7 @@ literal: else if (flags & SHORT) *va_arg(ap, short *) = res; else if (flags & SHORTSHORT) - *va_arg(ap, __signed char *) = res; + *va_arg(ap, signed char *) = res; else *va_arg(ap, int *) = res; nassigned++; diff --git a/libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c b/libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c index f76eed3e2..7cb08eabb 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/vfwprintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfwprintf.c,v 1.6 2013/04/17 17:40:35 tedu Exp $ */ +/* $OpenBSD: vfwprintf.c,v 1.9 2014/03/19 05:17:01 guenther Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -54,8 +54,6 @@ #include "local.h" #include "fvwrite.h" -wint_t __fputwc_unlock(wchar_t wc, FILE *fp); - union arg { int intarg; unsigned int uintarg; @@ -235,11 +233,10 @@ __mbsconv(char *mbsarg, int prec) #include #include #include "floatio.h" +#include "gdtoa.h" #define DEFPREC 6 -extern char *__dtoa(double, int, int, int *, int *, char **); -extern void __freedtoa(char *); static int exponent(wchar_t *, int, int); #endif /* FLOATING_POINT */ @@ -392,7 +389,7 @@ __vfwprintf(FILE * __restrict fp, const wchar_t * __restrict fmt0, __va_list ap) flags&PTRINT ? GETARG(ptrdiff_t) : \ flags&SIZEINT ? GETARG(ssize_t) : \ flags&SHORTINT ? (short)GETARG(int) : \ - flags&CHARINT ? (__signed char)GETARG(int) : \ + flags&CHARINT ? (signed char)GETARG(int) : \ GETARG(int))) #define UARG() \ ((uintmax_t)(flags&MAXINT ? GETARG(uintmax_t) : \ @@ -795,7 +792,7 @@ fp_common: else if (flags & SHORTINT) *GETARG(short *) = ret; else if (flags & CHARINT) - *GETARG(__signed char *) = ret; + *GETARG(signed char *) = ret; else if (flags & PTRINT) *GETARG(ptrdiff_t *) = ret; else if (flags & SIZEINT) diff --git a/libc/upstream-openbsd/lib/libc/stdio/vfwscanf.c b/libc/upstream-openbsd/lib/libc/stdio/vfwscanf.c index e5cf5e129..cbb36be34 100644 --- a/libc/upstream-openbsd/lib/libc/stdio/vfwscanf.c +++ b/libc/upstream-openbsd/lib/libc/stdio/vfwscanf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfwscanf.c,v 1.2 2012/01/18 17:23:11 chl Exp $ */ +/* $OpenBSD: vfwscanf.c,v 1.4 2014/03/19 05:17:01 guenther Exp $ */ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. @@ -31,7 +31,6 @@ * SUCH DAMAGE. */ -#include #include #include #include @@ -300,7 +299,7 @@ literal: if (flags & SUPPRESS) continue; if (flags & SHORTSHORT) - *va_arg(ap, __signed char *) = nread; + *va_arg(ap, signed char *) = nread; else if (flags & SHORT) *va_arg(ap, short *) = nread; else if (flags & LONG) @@ -324,7 +323,7 @@ literal: return (EOF); default: /* compat */ - if (isupper(c)) + if (iswupper(c)) flags |= LONG; c = CT_INT; base = 10; @@ -672,7 +671,7 @@ literal: else if (flags & SHORT) *va_arg(ap, short *) = res; else if (flags & SHORTSHORT) - *va_arg(ap, __signed char *) = res; + *va_arg(ap, signed char *) = res; else *va_arg(ap, int *) = res; nassigned++;