This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "uClibc-ng - small C library for embedded systems".
The branch, master has been updated
via bf70f6f1face8e36030544a74e5ea04903df16cb (commit)
via 4fee9155f396cb2bcfe707f78aa4332837520f93 (commit)
via 2e045f9867bfc62e64412bc039400d411da1d2d2 (commit)
from d80e49d7b6da04efac6ece21497d32b14abb089f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit bf70f6f1face8e36030544a74e5ea04903df16cb
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Wed Jun 8 21:49:04 2016 +0200
test: add new mmap tests from glibc
Rename mmap2 test as this is a ARM specific test, only
execute on ARM systems. Add more new tests from glibc.
commit 4fee9155f396cb2bcfe707f78aa4332837520f93
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Jun 7 04:14:23 2016 +0200
ssp: remove SSP legacy code
Nobody should use gcc 3.3 nowadays.
commit 2e045f9867bfc62e64412bc039400d411da1d2d2
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Jun 7 03:54:20 2016 +0200
microblaze: remove unused dead code
These files are not used, no regression found while
running the testsuite.
-----------------------------------------------------------------------
Summary of changes:
extra/Configs/Config.in | 16 ----
ldso/ldso/ldso.c | 6 --
libc/misc/internals/__uClibc_main.c | 7 --
libc/sysdeps/linux/common/ssp.c | 27 +-----
libc/sysdeps/linux/microblaze/Makefile.arch | 5 +-
libc/sysdeps/linux/microblaze/crt0.S | 52 -----------
libc/sysdeps/linux/microblaze/fixdfsi.c | 85 -----------------
libc/sysdeps/linux/microblaze/floatlib.h | 140 ----------------------------
test/mmap/Makefile.in | 6 ++
test/mmap/{mmap2.c => mmap-arm.c} | 0
test/mmap/tst-mmap-eofsync.c | 106 +++++++++++++++++++++
test/mmap/tst-mmap-fflushsync.c | 99 ++++++++++++++++++++
test/mmap/tst-mmap-offend.c | 86 +++++++++++++++++
test/mmap/tst-mmap-setvbuf.c | 81 ++++++++++++++++
14 files changed, 380 insertions(+), 336 deletions(-)
delete mode 100644 libc/sysdeps/linux/microblaze/crt0.S
delete mode 100644 libc/sysdeps/linux/microblaze/fixdfsi.c
delete mode 100644 libc/sysdeps/linux/microblaze/floatlib.h
create mode 100644 test/mmap/Makefile.in
rename test/mmap/{mmap2.c => mmap-arm.c} (100%)
create mode 100644 test/mmap/tst-mmap-eofsync.c
create mode 100644 test/mmap/tst-mmap-fflushsync.c
create mode 100644 test/mmap/tst-mmap-offend.c
create mode 100644 test/mmap/tst-mmap-setvbuf.c
diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
index f3494db..a21bdac 100644
--- a/extra/Configs/Config.in
+++ b/extra/Configs/Config.in
@@ -2151,22 +2151,6 @@ config UCLIBC_HAS_SSP
Most people will answer N.
-config UCLIBC_HAS_SSP_COMPAT
- bool "Support for gcc-3.x propolice smashing stack protector"
- depends on UCLIBC_HAS_SSP
- help
- Add gcc-3.x propolice smashing stack protector to the library.
-
- This requires a patched version of GCC, supporting the
- -fstack-protector[-all] options, with the __guard and
- __stack_smash_handler functions removed from libgcc.
- These functions are added to ldso/libc instead.
-
- More information at:
- <http://www.research.ibm.com/trl/projects/security/ssp/>
-
- Most people will answer N.
-
config SSP_QUICK_CANARY
bool "Use simple guard values without accessing /dev/urandom"
depends on UCLIBC_HAS_SSP
diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c
index 9f4e841..7bb6a34 100644
--- a/ldso/ldso/ldso.c
+++ b/ldso/ldso/ldso.c
@@ -120,9 +120,6 @@ static uintptr_t stack_chk_guard;
* in local thread area. */
uintptr_t __stack_chk_guard attribute_relro;
# endif
-# ifdef __UCLIBC_HAS_SSP_COMPAT__
-uintptr_t __guard attribute_relro;
-# endif
#endif
#ifdef __LDSO_SEARCH_INTERP_PATH__
@@ -1217,9 +1214,6 @@ of this helper program; chances are you did not intend to run this
program.\n\
# else
__stack_chk_guard = stack_chk_guard;
# endif
-# ifdef __UCLIBC_HAS_SSP_COMPAT__
- __guard = stack_chk_guard;
-# endif
#endif
#ifdef __LDSO_PRELINK_SUPPORT__
diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c
index 632a252..9bb81fc 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -61,10 +61,6 @@ static uintptr_t stack_chk_guard;
/* for gcc-4.1 non-TLS */
uintptr_t __stack_chk_guard attribute_relro;
# endif
-/* for gcc-3.x + Etoh ssp */
-# ifdef __UCLIBC_HAS_SSP_COMPAT__
-uintptr_t __guard attribute_relro;
-# endif
# endif
/*
@@ -274,9 +270,6 @@ void __uClibc_init(void)
# else
__stack_chk_guard = stack_chk_guard;
# endif
-# ifdef __UCLIBC_HAS_SSP_COMPAT__
- __guard = stack_chk_guard;
-# endif
# endif
#endif
diff --git a/libc/sysdeps/linux/common/ssp.c b/libc/sysdeps/linux/common/ssp.c
index 8dcc3dc..87e10c2 100644
--- a/libc/sysdeps/linux/common/ssp.c
+++ b/libc/sysdeps/linux/common/ssp.c
@@ -51,18 +51,11 @@ static void __cold do_msg(const char *msg1, const char *msg2, const
char *msg3)
}
static void __cold attribute_noreturn
-#ifdef __UCLIBC_HAS_SSP_COMPAT__
-ssp_handler(char func[])
-#else
ssp_handler(void)
-#endif
{
pid_t pid;
static const char msg_ssd[] = "*** stack smashing detected ***: ";
static const char msg_terminated[] = " terminated";
-#ifdef __UCLIBC_HAS_SSP_COMPAT__
- static const char msg_ssa[] = ": stack smashing attack in function ";
-#endif
#ifdef __DODEBUG__
struct sigaction sa;
@@ -73,12 +66,7 @@ ssp_handler(void)
sigprocmask(SIG_BLOCK, &mask, NULL); /* except SSP_SIGTYPE */
#endif
-#ifdef __UCLIBC_HAS_SSP_COMPAT__
- if (func != NULL)
- do_msg(__uclibc_progname, msg_ssa, func);
- else
-#endif
- do_msg(msg_ssd, __uclibc_progname, msg_terminated);
+ do_msg(msg_ssd, __uclibc_progname, msg_terminated);
pid = getpid();
#ifdef __DODEBUG__
@@ -96,20 +84,7 @@ ssp_handler(void)
_exit(127);
}
-#ifdef __UCLIBC_HAS_SSP_COMPAT__
-void __stack_smash_handler(char func[], int damaged) attribute_noreturn __cold;
-void __stack_smash_handler(char func[], int damaged attribute_unused)
-{
- ssp_handler(func);
-}
-
-void __stack_chk_fail(void)
-{
- ssp_handler(NULL);
-}
-#else
strong_alias(ssp_handler,__stack_chk_fail)
-#endif
#ifdef __UCLIBC_HAS_FORTIFY__
/* should be redone when activated to use common code above.
diff --git a/libc/sysdeps/linux/microblaze/Makefile.arch
b/libc/sysdeps/linux/microblaze/Makefile.arch
index 8f14fb9..6f1e9fb 100644
--- a/libc/sysdeps/linux/microblaze/Makefile.arch
+++ b/libc/sysdeps/linux/microblaze/Makefile.arch
@@ -5,8 +5,5 @@
#
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
-CSRC-y := clone.c fixdfsi.c
-
+CSRC-y := clone.c
SSRC-y := setjmp.S __longjmp.S vfork.S
-
-ARCH_HEADERS := floatlib.h
diff --git a/libc/sysdeps/linux/microblaze/crt0.S b/libc/sysdeps/linux/microblaze/crt0.S
deleted file mode 100644
index 6be1e4d..0000000
--- a/libc/sysdeps/linux/microblaze/crt0.S
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * libc/sysdeps/linux/microblaze/crt0.S -- Initial program entry point for
linux/microblaze
- *
- * Copyright (C) 2003 John Williams <jwilliams(a)itee.uq.edu.au>
- * Copyright (C) 2001,2002 NEC Corporation
- * Copyright (C) 2001,2002 Miles Bader <miles(a)gnu.org>
- *
- * This file is subject to the terms and conditions of the GNU Lesser
- * General Public License. See the file COPYING.LIB in the main
- * directory of this archive for more details.
- *
- * Written by Miles Bader <miles(a)gnu.org>
- */
-
-#include <clinkage.h>
-
-/* Upon entry, the stack contains the following data:
- argc, argv[0], ..., argv[argc-1], 0, envp[0], ..., 0
-*/
-
- .text
-C_ENTRY(_start):
- lw r5, r0, r1 /* Arg 0: argc */
-
- addi r6, r1, 4 /* Arg 1: argv */
-
- /* Arg 2: envp */
- addi r3, r5, 1 /* skip argc elements to get envp start */
- /* ...plus the NULL at the end of argv */
- add r3, r3, r3 /* Make word offset */
- add r3, r3, r3
- add r7, r6, r3 /* add to argv to get offset */
-
- /* tail-call uclibc's startup routine */
- brid C_SYMBOL_NAME(__uClibc_main)
- nop
-
-
-/* Stick in a dummy reference to `main', so that if an application
- is linking when the `main' function is in a static library (.a)
- we can be sure that `main' actually gets linked in. */
-L_dummy_main_reference:
- .long C_SYMBOL_NAME(main)
-
-/* Define a symbol for the first piece of initialized data. */
- .data
- .globl __data_start
-__data_start:
- .long 0
- .weak data_start
- data_start = __data_start
-
diff --git a/libc/sysdeps/linux/microblaze/fixdfsi.c
b/libc/sysdeps/linux/microblaze/fixdfsi.c
deleted file mode 100644
index 1611176..0000000
--- a/libc/sysdeps/linux/microblaze/fixdfsi.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
-** libgcc support for software floating point.
-** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved.
-** Permission is granted to do *anything* you want with this file,
-** commercial or otherwise, provided this message remains intact. So there!
-** I would appreciate receiving any updates/patches/changes that anyone
-** makes, and am willing to be the repository for said changes (am I
-** making a big mistake?).
-
-Warning! Only single-precision is actually implemented. This file
-won't really be much use until double-precision is supported.
-
-However, once that is done, this file might eventually become a
-replacement for libgcc1.c. It might also make possible
-cross-compilation for an IEEE target machine from a non-IEEE
-host such as a VAX.
-
-If you'd like to work on completing this, please talk to rms(a)gnu.ai.mit.edu.
-
---> Double precision floating support added by James Carlson on 20 April 1998.
-
-**
-** Pat Wood
-** Pipeline Associates, Inc.
-** pipeline!phw(a)motown.com or
-** sun!pipeline!phw or
-** uunet!motown!pipeline!phw
-**
-** 05/01/91 -- V1.0 -- first release to gcc mailing lists
-** 05/04/91 -- V1.1 -- added float and double prototypes and return values
-** -- fixed problems with adding and subtracting zero
-** -- fixed rounding in truncdfsf2
-** -- fixed SWAP define and tested on 386
-*/
-
-/*
-** The following are routines that replace the libgcc soft floating point
-** routines that are called automatically when -msoft-float is selected.
-** The support single and double precision IEEE format, with provisions
-** for byte-swapped machines (tested on 386). Some of the double-precision
-** routines work at full precision, but most of the hard ones simply punt
-** and call the single precision routines, producing a loss of accuracy.
-** long long support is not assumed or included.
-** Overall accuracy is close to IEEE (actually 68882) for single-precision
-** arithmetic. I think there may still be a 1 in 1000 chance of a bit
-** being rounded the wrong way during a multiply. I'm not fussy enough to
-** bother with it, but if anyone is, knock yourself out.
-**
-** Efficiency has only been addressed where it was obvious that something
-** would make a big difference. Anyone who wants to do this right for
-** best speed should go in and rewrite in assembler.
-**
-** I have tested this only on a 68030 workstation and 386/ix integrated
-** in with -msoft-float.
-*/
-
-#include "floatlib.h"
-
-/* convert double to int */
-long
-__fixdfsi (double a1)
-{
- register union double_long dl1;
- register int exp;
- register long l;
-
- dl1.d = a1;
-
- if (!dl1.l.upper && !dl1.l.lower)
- return (0);
-
- exp = EXPD (dl1) - EXCESSD - 31;
- l = MANTD (dl1);
-
- if (exp > 0)
- return SIGND(dl1) ? (1<<31) : ((1ul<<31)-1);
-
- /* shift down until exp = 0 or l = 0 */
- if (exp < 0 && exp > -32 && l)
- l >>= -exp;
- else
- return (0);
-
- return (SIGND (dl1) ? -l : l);
-}
diff --git a/libc/sysdeps/linux/microblaze/floatlib.h
b/libc/sysdeps/linux/microblaze/floatlib.h
deleted file mode 100644
index 817ba7d..0000000
--- a/libc/sysdeps/linux/microblaze/floatlib.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
-** libgcc support for software floating point.
-** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved.
-** Permission is granted to do *anything* you want with this file,
-** commercial or otherwise, provided this message remains intact. So there!
-** I would appreciate receiving any updates/patches/changes that anyone
-** makes, and am willing to be the repository for said changes (am I
-** making a big mistake?).
-
-Warning! Only single-precision is actually implemented. This file
-won't really be much use until double-precision is supported.
-
-However, once that is done, this file might eventually become a
-replacement for libgcc1.c. It might also make possible
-cross-compilation for an IEEE target machine from a non-IEEE
-host such as a VAX.
-
-If you'd like to work on completing this, please talk to rms(a)gnu.ai.mit.edu.
-
---> Double precision floating support added by James Carlson on 20 April 1998.
-
-**
-** Pat Wood
-** Pipeline Associates, Inc.
-** pipeline!phw(a)motown.com or
-** sun!pipeline!phw or
-** uunet!motown!pipeline!phw
-**
-** 05/01/91 -- V1.0 -- first release to gcc mailing lists
-** 05/04/91 -- V1.1 -- added float and double prototypes and return values
-** -- fixed problems with adding and subtracting zero
-** -- fixed rounding in truncdfsf2
-** -- fixed SWAP define and tested on 386
-*/
-
-/*
-** The following are routines that replace the libgcc soft floating point
-** routines that are called automatically when -msoft-float is selected.
-** The support single and double precision IEEE format, with provisions
-** for byte-swapped machines (tested on 386). Some of the double-precision
-** routines work at full precision, but most of the hard ones simply punt
-** and call the single precision routines, producing a loss of accuracy.
-** long long support is not assumed or included.
-** Overall accuracy is close to IEEE (actually 68882) for single-precision
-** arithmetic. I think there may still be a 1 in 1000 chance of a bit
-** being rounded the wrong way during a multiply. I'm not fussy enough to
-** bother with it, but if anyone is, knock yourself out.
-**
-** Efficiency has only been addressed where it was obvious that something
-** would make a big difference. Anyone who wants to do this right for
-** best speed should go in and rewrite in assembler.
-**
-** I have tested this only on a 68030 workstation and 386/ix integrated
-** in with -msoft-float.
-*/
-
-#ifndef __FLOAT_LIB_H__
-#define __FLOAT_LIB_H__
-/* the following deal with IEEE single-precision numbers */
-#define EXCESS 126
-#define SIGNBIT 0x80000000
-#define HIDDEN (1 << 23)
-#define SIGN(fp) ((fp) & SIGNBIT)
-#define EXP(fp) (((fp) >> 23) & 0xFF)
-#define MANT(fp) (((fp) & 0x7FFFFF) | HIDDEN)
-#define PACK(s,e,m) ((s) | ((e) << 23) | (m))
-
-/* the following deal with IEEE double-precision numbers */
-#define EXCESSD 1022
-#define HIDDEND (1 << 20)
-#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
-#define SIGND(fp) ((fp.l.upper) & SIGNBIT)
-#define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \
- (fp.l.lower >> 22))
-#define HIDDEND_LL ((long long)1 << 52)
-#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
-#define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m))
-
-/* define SWAP for 386/960 reverse-byte-order brain-damaged CPUs */
-union double_long {
- double d;
-#ifdef SWAP
- struct {
- unsigned long lower;
- long upper;
- } l;
-#else
- struct {
- long upper;
- unsigned long lower;
- } l;
-#endif
- long long ll;
-};
-
-union float_long
- {
- float f;
- long l;
- };
-
-#endif
-
-/* Functions defined in different files */
-
-float __addsf3 (float, float);
-float __subsf3 (float, float);
-long __cmpsf2 (float, float);
-float __mulsf3 (float, float);
-float __divsf3 (float, float);
-double __floatsidf (register long);
-double __floatdidf (register long long);
-float __floatsisf (register long );
-float __floatdisf (register long long );
-float __negsf2 (float);
-double __negdf2 (double);
-double __extendsfdf2 (float);
-float __truncdfsf2 (double);
-long __cmpdf2 (double, double);
-long __fixsfsi (float);
-long __fixdfsi (double);
-long long __fixdfdi (double);
-unsigned long __fixunsdfsi (double);
-unsigned long long __fixunsdfdi (double);
-double __adddf3 (double, double);
-double __subdf3 (double, double);
-double __muldf3 (double, double);
-double __divdf3 (double, double);
-int __gtdf2 (double, double);
-int __gedf2 (double, double);
-int __ltdf2 (double, double);
-int __ledf2 (double, double);
-int __eqdf2 (double, double);
-int __nedf2 (double, double);
-int __gtsf2 (float, float);
-int __gesf2 (float, float);
-int __ltsf2 (float, float);
-int __lesf2 (float, float);
-int __eqsf2 (float, float);
-int __nesf2 (float, float);
diff --git a/test/mmap/Makefile.in b/test/mmap/Makefile.in
new file mode 100644
index 0000000..7bb34ac
--- /dev/null
+++ b/test/mmap/Makefile.in
@@ -0,0 +1,6 @@
+# uClibc mmap tests
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+
+ifneq ($(TARGET_ARCH),arm)
+TESTS_DISABLED += mmap-arm
+endif
diff --git a/test/mmap/mmap2.c b/test/mmap/mmap-arm.c
similarity index 100%
rename from test/mmap/mmap2.c
rename to test/mmap/mmap-arm.c
diff --git a/test/mmap/tst-mmap-eofsync.c b/test/mmap/tst-mmap-eofsync.c
new file mode 100644
index 0000000..e8ef727
--- /dev/null
+++ b/test/mmap/tst-mmap-eofsync.c
@@ -0,0 +1,106 @@
+/* Test program for synchronization of stdio state with file after EOF. */
+
+#include <stdio.h>
+#include <error.h>
+#include <errno.h>
+
+static void do_prepare (void);
+#define PREPARE(argc, argv) do_prepare ()
+static int do_test (void);
+#define TEST_FUNCTION do_test ()
+#include <test-skeleton.c>
+
+static char *temp_file;
+static int temp_fd;
+
+static char text1[] = "Line the first\n";
+static char text2[] = "Line the second\n";
+
+static void
+do_prepare (void)
+{
+ temp_fd = create_temp_file ("tst-mmap-eofsync.", &temp_file);
+ if (temp_fd == -1)
+ error (1, errno, "cannot create temporary file");
+ else
+ {
+ ssize_t cc = write (temp_fd, text1, sizeof text1 - 1);
+ if (cc != sizeof text1 - 1)
+ error (1, errno, "cannot write to temporary file");
+ }
+}
+
+static int
+do_test (void)
+{
+ FILE *f;
+ char buf[128];
+ int result = 0;
+ int c;
+
+ f = fopen (temp_file, "rm");
+ if (f == NULL)
+ {
+ perror (temp_file);
+ return 1;
+ }
+
+ if (fgets (buf, sizeof buf, f) == NULL)
+ {
+ perror ("fgets");
+ return 1;
+ }
+
+ if (strcmp (buf, text1))
+ {
+ printf ("read \"%s\", expected \"%s\"\n", buf,
text1);
+ result = 1;
+ }
+
+ printf ("feof = %d, ferror = %d immediately after fgets\n",
+ feof (f), ferror (f));
+
+#if 1
+ c = fgetc (f);
+ if (c == EOF)
+ printf ("fgetc -> EOF (feof = %d, ferror = %d)\n",
+ feof (f), ferror (f));
+ else
+ {
+ printf ("fgetc returned %o (feof = %d, ferror = %d)\n",
+ c, feof (f), ferror (f));
+ result = 1;
+ }
+#endif
+
+ c = write (temp_fd, text2, sizeof text2 - 1);
+ if (c == sizeof text2 - 1)
+ printf ("wrote more to file\n");
+ else
+ {
+ printf ("wrote %d != %zd (%m)\n", c, sizeof text2 - 1);
+ result = 1;
+ }
+
+ if (fgets (buf, sizeof buf, f) == NULL)
+ {
+ printf ("second fgets fails: feof = %d, ferror = %d (%m)\n",
+ feof (f), ferror (f));
+ clearerr (f);
+ if (fgets (buf, sizeof buf, f) == NULL)
+ {
+ printf ("retry fgets fails: feof = %d, ferror = %d (%m)\n",
+ feof (f), ferror (f));
+ result = 1;
+ }
+ }
+ if (result == 0 && strcmp (buf, text2))
+ {
+ printf ("second time read \"%s\", expected \"%s\"\n",
buf, text2);
+ result = 1;
+ }
+
+ fclose (f);
+
+ return result;
+}
diff --git a/test/mmap/tst-mmap-fflushsync.c b/test/mmap/tst-mmap-fflushsync.c
new file mode 100644
index 0000000..24ae33c
--- /dev/null
+++ b/test/mmap/tst-mmap-fflushsync.c
@@ -0,0 +1,99 @@
+/* Test program for synchronization of stdio state with file after fflush. */
+
+#include <stdio.h>
+#include <error.h>
+#include <errno.h>
+
+static void do_prepare (void);
+#define PREPARE(argc, argv) do_prepare ()
+static int do_test (void);
+#define TEST_FUNCTION do_test ()
+#include <test-skeleton.c>
+
+static char *temp_file;
+static int temp_fd;
+
+static char text1[] = "Line the first\n";
+static char text2[] = "Line the second\n";
+
+static void
+do_prepare (void)
+{
+ temp_fd = create_temp_file ("tst-mmap-eofsync.", &temp_file);
+ if (temp_fd == -1)
+ error (1, errno, "cannot create temporary file");
+ else
+ {
+ ssize_t cc = write (temp_fd, text1, sizeof text1 - 1);
+ if (cc != sizeof text1 - 1)
+ error (1, errno, "cannot write to temporary file");
+ }
+}
+
+static int
+do_test (void)
+{
+ FILE *f;
+ char buf[128];
+ int result = 0;
+ int c;
+
+ f = fopen (temp_file, "rm");
+ if (f == NULL)
+ {
+ perror (temp_file);
+ return 1;
+ }
+
+ if (fgets (buf, sizeof buf, f) == NULL)
+ {
+ perror ("fgets");
+ return 1;
+ }
+
+ if (strcmp (buf, text1))
+ {
+ printf ("read \"%s\", expected \"%s\"\n", buf,
text1);
+ result = 1;
+ }
+
+ printf ("feof = %d, ferror = %d immediately after fgets\n",
+ feof (f), ferror (f));
+
+ if (fflush (f) != 0)
+ {
+ printf ("fflush failed! %m\n");
+ result = 1;
+ }
+
+ c = write (temp_fd, text2, sizeof text2 - 1);
+ if (c == sizeof text2 - 1)
+ printf ("wrote more to file\n");
+ else
+ {
+ printf ("wrote %d != %zd (%m)\n", c, sizeof text2 - 1);
+ result = 1;
+ }
+
+ if (fgets (buf, sizeof buf, f) == NULL)
+ {
+ printf ("second fgets fails: feof = %d, ferror = %d (%m)\n",
+ feof (f), ferror (f));
+ clearerr (f);
+ if (fgets (buf, sizeof buf, f) == NULL)
+ {
+ printf ("retry fgets fails: feof = %d, ferror = %d (%m)\n",
+ feof (f), ferror (f));
+ result = 1;
+ }
+ }
+ if (result == 0 && strcmp (buf, text2))
+ {
+ printf ("second time read \"%s\", expected \"%s\"\n",
buf, text2);
+ result = 1;
+ }
+
+ fclose (f);
+
+ return result;
+}
diff --git a/test/mmap/tst-mmap-offend.c b/test/mmap/tst-mmap-offend.c
new file mode 100644
index 0000000..19732e6
--- /dev/null
+++ b/test/mmap/tst-mmap-offend.c
@@ -0,0 +1,86 @@
+/* Test case for bug with mmap stdio read past end of file. */
+
+#include <stdio.h>
+#include <error.h>
+#include <errno.h>
+
+static void do_prepare (void);
+#define PREPARE(argc, argv) do_prepare ()
+static int do_test (void);
+#define TEST_FUNCTION do_test ()
+#include <test-skeleton.c>
+
+static char *temp_file;
+
+static const char text1[] = "hello\n";
+
+static void
+do_prepare (void)
+{
+ int temp_fd = create_temp_file ("tst-mmap-offend.", &temp_file);
+ if (temp_fd == -1)
+ error (1, errno, "cannot create temporary file");
+ else
+ {
+ ssize_t cc = write (temp_fd, text1, sizeof text1 - 1);
+ if (cc != sizeof text1 - 1)
+ error (1, errno, "cannot write to temporary file");
+ }
+ close (temp_fd);
+}
+
+static int
+do_test (void)
+{
+ unsigned char buffer[8192];
+ int result = 0;
+ FILE *f = fopen (temp_file, "rm");
+ size_t cc;
+
+ if (f == NULL)
+ {
+ perror (temp_file);
+ return 1;
+ }
+
+ cc = fread (buffer, 1, sizeof (buffer), f);
+ printf ("fread %zu: \"%.*s\"\n", cc, (int) cc, buffer);
+ if (cc != sizeof text1 - 1)
+ {
+ perror ("fread");
+ result = 1;
+ }
+
+ if (fseek (f, 2048, SEEK_SET) != 0)
+ {
+ perror ("fseek off end");
+ result = 1;
+ }
+
+ if (fread (buffer, 1, sizeof (buffer), f) != 0
+ || ferror (f) || !feof (f))
+ {
+ printf ("after fread error %d eof %d\n",
+ ferror (f), feof (f));
+ result = 1;
+ }
+
+ printf ("ftell %ld\n", ftell (f));
+
+ if (fseek (f, 0, SEEK_SET) != 0)
+ {
+ perror ("fseek rewind");
+ result = 1;
+ }
+
+ cc = fread (buffer, 1, sizeof (buffer), f);
+ printf ("fread after rewind %zu: \"%.*s\"\n", cc, (int) cc,
buffer);
+ if (cc != sizeof text1 - 1)
+ {
+ perror ("fread after rewind");
+ result = 1;
+ }
+
+ fclose (f);
+ return result;
+}
diff --git a/test/mmap/tst-mmap-setvbuf.c b/test/mmap/tst-mmap-setvbuf.c
new file mode 100644
index 0000000..33d60b7
--- /dev/null
+++ b/test/mmap/tst-mmap-setvbuf.c
@@ -0,0 +1,81 @@
+/* Test setvbuf on readonly fopen (using mmap stdio).
+ Copyright (C) 2002-2016 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Jakub Jelinek <jakub(a)redhat.com>om>, 2002.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int main (void)
+{
+ char name[] = "/tmp/tst-mmap-setvbuf.XXXXXX";
+ char buf[4096];
+ const char * const test = "Let's see if mmap stdio works with
setvbuf.\n";
+ char temp[strlen (test) + 1];
+ int fd = mkstemp (name);
+ FILE *f;
+
+ if (fd == -1)
+ {
+ printf ("%u: cannot open temporary file: %m\n", __LINE__);
+ exit (1);
+ }
+
+ f = fdopen (fd, "w");
+ if (f == NULL)
+ {
+ printf ("%u: cannot fdopen temporary file: %m\n", __LINE__);
+ exit (1);
+ }
+
+ fputs (test, f);
+ fclose (f);
+
+ f = fopen (name, "rm");
+ if (f == NULL)
+ {
+ printf ("%u: cannot fopen temporary file: %m\n", __LINE__);
+ exit (1);
+ }
+
+ if (setvbuf (f, buf, _IOFBF, sizeof buf))
+ {
+ printf ("%u: setvbuf failed: %m\n", __LINE__);
+ exit (1);
+ }
+
+ if (fread (temp, 1, strlen (test), f) != strlen (test))
+ {
+ printf ("%u: couldn't read the file back: %m\n", __LINE__);
+ exit (1);
+ }
+ temp [strlen (test)] = '\0';
+
+ if (strcmp (test, temp))
+ {
+ printf ("%u: read different string than was written:\n%s%s",
+ __LINE__, test, temp);
+ exit (1);
+ }
+
+ fclose (f);
+
+ unlink (name);
+ exit (0);
+}
hooks/post-receive
--
uClibc-ng - small C library for embedded systems