am bab07de0: am ad534985: Merge "Disable %n in printf and vfwprintf."

* commit 'bab07de0bc43a284647465dc167bcf5b63891eb6':
  Disable %n in printf and vfwprintf.
This commit is contained in:
Elliott Hughes 2014-05-05 21:55:46 +00:00 committed by Android Git Automerger
commit c13ea3e236
4 changed files with 20 additions and 6 deletions
libc
stdio
upstream-openbsd/lib/libc/stdio
tests

@ -102,6 +102,7 @@ extern int __sdidinit;
#define FLOATING_POINT #define FLOATING_POINT
#define PRINTF_WIDE_CHAR #define PRINTF_WIDE_CHAR
#define SCANF_WIDE_CHAR #define SCANF_WIDE_CHAR
#define NO_PRINTF_PERCENT_N
/* OpenBSD exposes these in <stdio.h>, but we only want them exposed to the implementation. */ /* OpenBSD exposes these in <stdio.h>, but we only want them exposed to the implementation. */
__BEGIN_DECLS __BEGIN_DECLS

@ -1,4 +1,4 @@
/* $OpenBSD: vfprintf.c,v 1.65 2014/03/19 05:17:01 guenther Exp $ */ /* $OpenBSD: vfprintf.c,v 1.66 2014/05/03 12:36:45 deraadt Exp $ */
/*- /*-
* Copyright (c) 1990 The Regents of the University of California. * Copyright (c) 1990 The Regents of the University of California.
* All rights reserved. * All rights reserved.
@ -801,6 +801,7 @@ fp_common:
} }
break; break;
#endif /* FLOATING_POINT */ #endif /* FLOATING_POINT */
#ifndef NO_PRINTF_PERCENT_N
case 'n': case 'n':
if (flags & LLONGINT) if (flags & LLONGINT)
*GETARG(long long *) = ret; *GETARG(long long *) = ret;
@ -819,6 +820,7 @@ fp_common:
else else
*GETARG(int *) = ret; *GETARG(int *) = ret;
continue; /* no output */ continue; /* no output */
#endif /* NO_PRINTF_PERCENT_N */
case 'O': case 'O':
flags |= LONGINT; flags |= LONGINT;
/*FALLTHROUGH*/ /*FALLTHROUGH*/
@ -1317,6 +1319,7 @@ reswitch: switch (ch) {
ADDTYPE(T_DOUBLE); ADDTYPE(T_DOUBLE);
break; break;
#endif /* FLOATING_POINT */ #endif /* FLOATING_POINT */
#ifndef NO_PRINTF_PERCENT_N
case 'n': case 'n':
if (flags & LLONGINT) if (flags & LLONGINT)
ADDTYPE(TP_LLONG); ADDTYPE(TP_LLONG);
@ -1333,6 +1336,7 @@ reswitch: switch (ch) {
else else
ADDTYPE(TP_INT); ADDTYPE(TP_INT);
continue; /* no output */ continue; /* no output */
#endif /* NO_PRINTF_PERCENT_N */
case 'O': case 'O':
flags |= LONGINT; flags |= LONGINT;
/*FALLTHROUGH*/ /*FALLTHROUGH*/

@ -1,4 +1,4 @@
/* $OpenBSD: vfwprintf.c,v 1.9 2014/03/19 05:17:01 guenther Exp $ */ /* $OpenBSD: vfwprintf.c,v 1.10 2014/05/03 12:36:45 deraadt Exp $ */
/*- /*-
* Copyright (c) 1990 The Regents of the University of California. * Copyright (c) 1990 The Regents of the University of California.
* All rights reserved. * All rights reserved.
@ -784,6 +784,7 @@ fp_common:
} }
break; break;
#endif /* FLOATING_POINT */ #endif /* FLOATING_POINT */
#ifndef NO_PRINTF_PERCENT_N
case 'n': case 'n':
if (flags & LLONGINT) if (flags & LLONGINT)
*GETARG(long long *) = ret; *GETARG(long long *) = ret;
@ -802,6 +803,7 @@ fp_common:
else else
*GETARG(int *) = ret; *GETARG(int *) = ret;
continue; /* no output */ continue; /* no output */
#endif /* NO_PRINTF_PERCENT_N */
case 'O': case 'O':
flags |= LONGINT; flags |= LONGINT;
/*FALLTHROUGH*/ /*FALLTHROUGH*/
@ -1296,6 +1298,7 @@ reswitch: switch (ch) {
ADDTYPE(T_DOUBLE); ADDTYPE(T_DOUBLE);
break; break;
#endif /* FLOATING_POINT */ #endif /* FLOATING_POINT */
#ifndef NO_PRINTF_PERCENT_N
case 'n': case 'n':
if (flags & LLONGINT) if (flags & LLONGINT)
ADDTYPE(TP_LLONG); ADDTYPE(TP_LLONG);
@ -1312,6 +1315,7 @@ reswitch: switch (ch) {
else else
ADDTYPE(TP_INT); ADDTYPE(TP_INT);
continue; /* no output */ continue; /* no output */
#endif /* NO_PRINTF_PERCENT_N */
case 'O': case 'O':
flags |= LONGINT; flags |= LONGINT;
/*FALLTHROUGH*/ /*FALLTHROUGH*/

@ -220,11 +220,16 @@ TEST(stdio, snprintf_ls) {
} }
TEST(stdio, snprintf_n) { TEST(stdio, snprintf_n) {
#if !defined(__GLIBC__)
// http://b/14492135
char buf[32]; char buf[32];
int i = 0; int i = 1234;
EXPECT_EQ(4, snprintf(buf, sizeof(buf), "a %n b", &i)); EXPECT_EQ(5, snprintf(buf, sizeof(buf), "a %n b", &i));
EXPECT_EQ(2, i); EXPECT_EQ(1234, i);
EXPECT_STREQ("a b", buf); EXPECT_STREQ("a n b", buf);
#else
GTEST_LOG_(INFO) << "This test does nothing.\n";
#endif
} }
TEST(stdio, snprintf_smoke) { TEST(stdio, snprintf_smoke) {