Skip to content

Commit

Permalink
[BZ #779]
Browse files Browse the repository at this point in the history
2005-03-10  Jakub Jelinek  <jakub@redhat.com>
	* math/test-misc.c (main): Add some more tests.

2005-03-17  Jakub Jelinek  <jakub@redhat.com>

	* posix/regcomp.c (re_compile_fastmap_iter): Fix check for failed
	__wcrtomb.  Check return values of other __wcrtomb calls.
	* posix/regex_internal.c (build_wcs_buffer, re_string_skip_chars):
	Change mbclen type to size_t.
	(build_wcs_upper_buffer): Change mbclen and mbcdlen type to size_t.
	Handle mb chars whose upper case doesn't have multibyte representation
	in locale's charset.

2005-03-15  Jakub Jelinek  <jakub@redhat.com>

	* malloc/malloc.c (_int_icalloc, _int_icomalloc, iALLOc,
	public_iCALLOc, public_iCALLOc, public_iCOMALLOc): Protect with
	#ifndef _LIBC.

	[BZ #779]
	* malloc/malloc.c (public_mTRIm): Initialize malloc if not yet
	initialized.

2005-03-10  Jakub Jelinek  <jakub@redhat.com>

	* misc/sys/cdefs.h (__always_inline): Define.
	* posix/bits/unistd.h (read, pread, pread64, readlink, getcwd, getwd):
	Use __always_inline instead of __inline.
	* socket/bits/socket2.h (recv, recvfrom): Likewise.
	* libio/bits/stdio2.h (gets, fgets, fgets_unlocked): Likewise.
	* string/bits/string3.h (__memcpy_ichk, __memmove_ichk, __mempcpy_ichk,
	__memset_ichk, __strcpy_ichk, __stpcpy_ichk, __strncpy_ichk,
	__strcat_ichk, __strncat_ichk): Use __always_inline instead of
	__inline__ __attribute__ ((__always_inline__)).

2005-03-09  Jakub Jelinek  <jakub@redhat.com>

	* debug/tst-chk1.c: Include sys/socket.h and sys/un.h.
	(do_test): Add new tests for recv, recvfrom, getcwd, getwd and
	readlink.  Add some more tests for read, pread, pread64, fgets and
	fgets_unlocked.

	* posix/bits/unistd.h (read, pread, pread64, readlink,
	getcwd, getwd): Change macros into extern inline functions.
	(__read_alias, __pread_alias, __pread64_alias, __readlink_alias,
	__getcwd_alias, __getwd_alias): New prototypes.
	* socket/bits/socket2.h (recv, recvfrom): Change macros into
	extern inline functions.
	(__recv_alias, __recvfrom_alias): New prototypes.
	* libio/bits/stdio2.h (gets, fgets, fgets_unlocked): Change macros
	into extern inline functions.
	(__gets_alias, __fgets_alias, __fgets_unlocked_alias): New prototypes.

	* debug/pread_chk.c (__pread_chk): Fix order of arguments passed
	to __pread.
	* debug/pread64_chk.c (__pread64_chk): Fix order of arguments passed
	to __pread64.
  • Loading branch information
Ulrich Drepper committed Mar 19, 2005
1 parent 60bd9f7 commit 88764ae
Show file tree
Hide file tree
Showing 13 changed files with 459 additions and 77 deletions.
60 changes: 59 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,7 +1,65 @@
2005-03-10 Jakub Jelinek <jakub@redhat.com>

* math/test-misc.c (main): Add some more tests.

2005-03-17 Jakub Jelinek <jakub@redhat.com>

* posix/regcomp.c (re_compile_fastmap_iter): Fix check for failed
__wcrtomb. Check return values of other __wcrtomb calls.
* posix/regex_internal.c (build_wcs_buffer, re_string_skip_chars):
Change mbclen type to size_t.
(build_wcs_upper_buffer): Change mbclen and mbcdlen type to size_t.
Handle mb chars whose upper case doesn't have multibyte representation
in locale's charset.

2005-03-15 Jakub Jelinek <jakub@redhat.com>

* malloc/malloc.c (_int_icalloc, _int_icomalloc, iALLOc,
public_iCALLOc, public_iCALLOc, public_iCOMALLOc): Protect with
#ifndef _LIBC.

[BZ #779]
* malloc/malloc.c (public_mTRIm): Initialize malloc if not yet
initialized.

2005-03-10 Jakub Jelinek <jakub@redhat.com>

* misc/sys/cdefs.h (__always_inline): Define.
* posix/bits/unistd.h (read, pread, pread64, readlink, getcwd, getwd):
Use __always_inline instead of __inline.
* socket/bits/socket2.h (recv, recvfrom): Likewise.
* libio/bits/stdio2.h (gets, fgets, fgets_unlocked): Likewise.
* string/bits/string3.h (__memcpy_ichk, __memmove_ichk, __mempcpy_ichk,
__memset_ichk, __strcpy_ichk, __stpcpy_ichk, __strncpy_ichk,
__strcat_ichk, __strncat_ichk): Use __always_inline instead of
__inline__ __attribute__ ((__always_inline__)).

2005-03-09 Jakub Jelinek <jakub@redhat.com>

* debug/tst-chk1.c: Include sys/socket.h and sys/un.h.
(do_test): Add new tests for recv, recvfrom, getcwd, getwd and
readlink. Add some more tests for read, pread, pread64, fgets and
fgets_unlocked.

* posix/bits/unistd.h (read, pread, pread64, readlink,
getcwd, getwd): Change macros into extern inline functions.
(__read_alias, __pread_alias, __pread64_alias, __readlink_alias,
__getcwd_alias, __getwd_alias): New prototypes.
* socket/bits/socket2.h (recv, recvfrom): Change macros into
extern inline functions.
(__recv_alias, __recvfrom_alias): New prototypes.
* libio/bits/stdio2.h (gets, fgets, fgets_unlocked): Change macros
into extern inline functions.
(__gets_alias, __fgets_alias, __fgets_unlocked_alias): New prototypes.

* debug/pread_chk.c (__pread_chk): Fix order of arguments passed
to __pread.
* debug/pread64_chk.c (__pread64_chk): Fix order of arguments passed
to __pread64.

2005-03-18 Daniel Jacobowitz <dan@codesourcery.com>

* configure.in: Use %function instead of @function.
* configure: Regenerated.

2005-03-18 Ulrich Drepper <drepper@redhat.com>

Expand Down
2 changes: 1 addition & 1 deletion debug/pread64_chk.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ __pread64_chk (int fd, void *buf, size_t nbytes, off64_t offset, size_t buflen)
if (nbytes > buflen)
__chk_fail ();

return __pread64 (fd, buf, offset, nbytes);
return __pread64 (fd, buf, nbytes, offset);
}
2 changes: 1 addition & 1 deletion debug/pread_chk.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ __pread_chk (int fd, void *buf, size_t nbytes, off_t offset, size_t buflen)
if (nbytes > buflen)
__chk_fail ();

return __pread (fd, buf, offset, nbytes);
return __pread (fd, buf, nbytes, offset);
}
231 changes: 226 additions & 5 deletions debug/tst-chk1.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>

char *temp_filename;
Expand Down Expand Up @@ -463,11 +465,22 @@ do_test (void)
if (fgets (buf, sizeof (buf), stdin) != buf || memcmp (buf, "ABCDEFGHI", 10))
FAIL ();

rewind (stdin);

if (fgets (buf, l0 + sizeof (buf), stdin) != buf
|| memcmp (buf, "abcdefgh\n", 10))
FAIL ();

#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
if (fgets (buf, sizeof (buf) + 1, stdin) != buf)
FAIL ();
CHK_FAIL_END

CHK_FAIL_START
if (fgets (buf, l0 + sizeof (buf) + 1, stdin) != buf)
FAIL ();
CHK_FAIL_END
#endif

rewind (stdin);
Expand All @@ -479,11 +492,22 @@ do_test (void)
|| memcmp (buf, "ABCDEFGHI", 10))
FAIL ();

rewind (stdin);

if (fgets_unlocked (buf, l0 + sizeof (buf), stdin) != buf
|| memcmp (buf, "abcdefgh\n", 10))
FAIL ();

#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
if (fgets_unlocked (buf, sizeof (buf) + 1, stdin) != buf)
FAIL ();
CHK_FAIL_END

CHK_FAIL_START
if (fgets_unlocked (buf, l0 + sizeof (buf) + 1, stdin) != buf)
FAIL ();
CHK_FAIL_END
#endif

lseek (fileno (stdin), 0, SEEK_SET);
Expand All @@ -495,19 +519,29 @@ do_test (void)
|| memcmp (buf, "ABCDEFGHI", 9))
FAIL ();

lseek (fileno (stdin), 0, SEEK_SET);

if (read (fileno (stdin), buf, l0 + sizeof (buf) - 1) != sizeof (buf) - 1
|| memcmp (buf, "abcdefgh\n", 9))
FAIL ();

#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
if (read (fileno (stdin), buf, sizeof (buf) + 1) != sizeof (buf) + 1)
FAIL ();
CHK_FAIL_END
#endif

if (pread (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 2)
!= sizeof (buf) - 1
|| memcmp (buf, "\nABCDEFGH", 9))
FAIL ();
if (pread (fileno (stdin), buf, sizeof (buf) - 1, 0) != sizeof (buf) - 1
|| memcmp (buf, "abcdefgh\n", 9))
FAIL ();
if (pread (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 1)
if (pread (fileno (stdin), buf, l0 + sizeof (buf) - 1, sizeof (buf) - 3)
!= sizeof (buf) - 1
|| memcmp (buf, "ABCDEFGHI", 9))
|| memcmp (buf, "h\nABCDEFG", 9))
FAIL ();

#if __USE_FORTIFY_LEVEL >= 1
Expand All @@ -518,17 +552,21 @@ do_test (void)
CHK_FAIL_END
#endif

if (pread64 (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 2)
!= sizeof (buf) - 1
|| memcmp (buf, "\nABCDEFGH", 9))
FAIL ();
if (pread64 (fileno (stdin), buf, sizeof (buf) - 1, 0) != sizeof (buf) - 1
|| memcmp (buf, "abcdefgh\n", 9))
FAIL ();
if (pread64 (fileno (stdin), buf, sizeof (buf) - 1, sizeof (buf) - 1)
if (pread64 (fileno (stdin), buf, l0 + sizeof (buf) - 1, sizeof (buf) - 3)
!= sizeof (buf) - 1
|| memcmp (buf, "ABCDEFGHI", 9))
|| memcmp (buf, "h\nABCDEFG", 9))
FAIL ();

#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
if (pread64 (fileno (stdin), buf, sizeof (buf) + 1, 2 * (sizeof (buf) - 1))
if (pread64 (fileno (stdin), buf, sizeof (buf) + 1, 2 * sizeof (buf))
!= sizeof (buf) + 1)
FAIL ();
CHK_FAIL_END
Expand Down Expand Up @@ -570,5 +608,188 @@ do_test (void)
snprintf (buf, sizeof (buf), "%3$d\n", 1, 2, 3, 4);
CHK_FAIL2_END

int sp[2];
if (socketpair (PF_UNIX, SOCK_STREAM, 0, sp))
FAIL ();
else
{
const char *sendstr = "abcdefgh\nABCDEFGH\n0123456789\n";
if (send (sp[0], sendstr, strlen (sendstr), 0) != strlen (sendstr))
FAIL ();

char recvbuf[12];
if (recv (sp[1], recvbuf, sizeof recvbuf, MSG_PEEK)
!= sizeof recvbuf
|| memcmp (recvbuf, sendstr, sizeof recvbuf) != 0)
FAIL ();

if (recv (sp[1], recvbuf + 6, l0 + sizeof recvbuf - 7, MSG_PEEK)
!= sizeof recvbuf - 7
|| memcmp (recvbuf + 6, sendstr, sizeof recvbuf - 7) != 0)
FAIL ();

#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
if (recv (sp[1], recvbuf + 1, sizeof recvbuf, MSG_PEEK)
!= sizeof recvbuf)
FAIL ();
CHK_FAIL_END

CHK_FAIL_START
if (recv (sp[1], recvbuf + 4, l0 + sizeof recvbuf - 3, MSG_PEEK)
!= sizeof recvbuf - 3)
FAIL ();
CHK_FAIL_END
#endif

socklen_t sl;
struct sockaddr_un sa_un;

sl = sizeof (sa_un);
if (recvfrom (sp[1], recvbuf, sizeof recvbuf, MSG_PEEK, &sa_un, &sl)
!= sizeof recvbuf
|| memcmp (recvbuf, sendstr, sizeof recvbuf) != 0)
FAIL ();

sl = sizeof (sa_un);
if (recvfrom (sp[1], recvbuf + 6, l0 + sizeof recvbuf - 7, MSG_PEEK,
&sa_un, &sl) != sizeof recvbuf - 7
|| memcmp (recvbuf + 6, sendstr, sizeof recvbuf - 7) != 0)
FAIL ();

#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
sl = sizeof (sa_un);
if (recvfrom (sp[1], recvbuf + 1, sizeof recvbuf, MSG_PEEK, &sa_un, &sl)
!= sizeof recvbuf)
FAIL ();
CHK_FAIL_END

CHK_FAIL_START
sl = sizeof (sa_un);
if (recvfrom (sp[1], recvbuf + 4, l0 + sizeof recvbuf - 3, MSG_PEEK,
&sa_un, &sl) != sizeof recvbuf - 3)
FAIL ();
CHK_FAIL_END
#endif

close (sp[0]);
close (sp[1]);
}

char fname[] = "/tmp/tst-chk1-dir-XXXXXX\0foo";
char *enddir = strchr (fname, '\0');
if (mkdtemp (fname) == NULL)
{
printf ("mkdtemp failed: %m\n");
return 1;
}
*enddir = '/';
if (symlink ("bar", fname) != 0)
FAIL ();

char readlinkbuf[4];
if (readlink (fname, readlinkbuf, 4) != 3
|| memcmp (readlinkbuf, "bar", 3) != 0)
FAIL ();
if (readlink (fname, readlinkbuf + 1, l0 + 3) != 3
|| memcmp (readlinkbuf, "bbar", 4) != 0)
FAIL ();

#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
if (readlink (fname, readlinkbuf + 2, l0 + 3) != 3)
FAIL ();
CHK_FAIL_END

CHK_FAIL_START
if (readlink (fname, readlinkbuf + 3, 4) != 3)
FAIL ();
CHK_FAIL_END
#endif

char *cwd1 = getcwd (NULL, 0);
if (cwd1 == NULL)
FAIL ();

char *cwd2 = getcwd (NULL, 250);
if (cwd2 == NULL)
FAIL ();

if (cwd1 && cwd2)
{
if (strcmp (cwd1, cwd2) != 0)
FAIL ();

*enddir = '\0';
if (chdir (fname))
FAIL ();

char *cwd3 = getcwd (NULL, 0);
if (cwd3 == NULL)
FAIL ();
if (strcmp (fname, cwd3) != 0)
printf ("getcwd after chdir is '%s' != '%s',"
"get{c,}wd tests skipped\n", cwd3, fname);
else
{
char getcwdbuf[sizeof fname - 3];

char *cwd4 = getcwd (getcwdbuf, sizeof getcwdbuf);
if (cwd4 != getcwdbuf
|| strcmp (getcwdbuf, fname) != 0)
FAIL ();

cwd4 = getcwd (getcwdbuf + 1, l0 + sizeof getcwdbuf - 1);
if (cwd4 != getcwdbuf + 1
|| getcwdbuf[0] != fname[0]
|| strcmp (getcwdbuf + 1, fname) != 0)
FAIL ();

#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
if (getcwd (getcwdbuf + 2, l0 + sizeof getcwdbuf)
!= getcwdbuf + 2)
FAIL ();
CHK_FAIL_END

CHK_FAIL_START
if (getcwd (getcwdbuf + 2, sizeof getcwdbuf)
!= getcwdbuf + 2)
FAIL ();
CHK_FAIL_END
#endif

if (getwd (getcwdbuf) != getcwdbuf
|| strcmp (getcwdbuf, fname) != 0)
FAIL ();

if (getwd (getcwdbuf + 1) != getcwdbuf + 1
|| strcmp (getcwdbuf + 1, fname) != 0)
FAIL ();

#if __USE_FORTIFY_LEVEL >= 1
CHK_FAIL_START
if (getwd (getcwdbuf + 2) != getcwdbuf + 2)
FAIL ();
CHK_FAIL_END
#endif
}

if (chdir (cwd1) != 0)
FAIL ();
free (cwd3);
}

free (cwd1);
free (cwd2);
*enddir = '/';
if (unlink (fname) != 0)
FAIL ();

*enddir = '\0';
if (rmdir (fname) != 0)
FAIL ();

return ret;
}
Loading

0 comments on commit 88764ae

Please sign in to comment.