Bug 2414

Summary: bug in stdlib/tst-setcontext.c
Product: glibc Reporter: Petr.Salinger
Component: libcAssignee: Ulrich Drepper <drepper.fsp>
Status: RESOLVED FIXED    
Severity: normal CC: glibc-bugs
Priority: P2 Flags: fweimer: security-
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Petr.Salinger 2006-03-03 10:52:22 UTC
Hi, 

there is a bug in testsuite, in testing of makecontext().
Prototype is  void makecontext(ucontext_t *ucp, void (*func)(),  int argc, ...);
As func() in testing is used function
static void f1 (long a0, long a1, long a2, long a3)

The actual call is 
 makecontext (&ctx[1], (void (*) (void)) f1, 4, 1, 2, 3, -4);

This is wrong, because standard C convention for parameter expanding are used,
i.e. all numbers are passed as ints not as longs.

Please fix it by either:

A) change prototype of f1() to use int
-------------------------------------------------

--- tst-setcontext.c    2006-03-02 22:37:00.000000000 +0100
+++ tst-setcontext.c     2006-03-02 22:14:41.000000000 +0100
@@ -30,7 +30,7 @@
 static char st2[32768];
 
 static void
-f1 (long a0, long a1, long a2, long a3)
+f1 (int a0, int a1, int a2, int a3)
 {
   printf ("start f1(a0=%lx,a1=%lx,a2=%lx,a3=%lx)\n", a0, a1, a2, a3);
 

B) pass long when calling makecontext
----------------------------------------------------

--- tst-setcontext.c    2006-03-02 22:37:00.000000000 +0100
+++ tst-setcontext.c     2006-03-02 22:15:13.000000000 +0100
@@ -158,7 +158,7 @@
   ctx[1].uc_link = &ctx[0];
   {
     ucontext_t tempctx = ctx[1];
-    makecontext (&ctx[1], (void (*) (void)) f1, 4, 1, 2, 3, -4);
+    makecontext (&ctx[1], (void (*) (void)) f1, 4, 1L, 2L, 3L, -4L);
 
     /* Without this check, a stub makecontext can make us spin forever.  */
     if (memcmp (&tempctx, &ctx[1], sizeof ctx[1]) == 0)

C) properly extend the test
-----------------------------------
test can be easily changed to test passing arguments of type int, long and pointer 

Option A) conform to current standard, it  requires only arguments of type int
to work,
from http://www.opengroup.org/onlinepubs/009695399/functions/makecontext.html
"The application shall ensure that the value of argc matches the number of
arguments of type int passed to func; otherwise, the behavior is undefined."

Option C) would test makecontext() against all reasonable passed argument types
Clarification of "int only" have beed added to IEEE Std 1003.1 in Issue 6,
previously there was no such restriction.

Petr
Comment 1 Sourceware Commits 2006-03-03 11:51:34 UTC
Subject: Bug 2414

CVSROOT:	/cvs/glibc
Module name:	libc
Changes by:	roland@sources.redhat.com	2006-03-03 11:51:31

Modified files:
	stdlib         : tst-setcontext.c 

Log message:
	2006-03-03  Roland McGrath  <roland@redhat.com>
	
	[BZ #2414]
	* stdlib/tst-setcontext.c (f1): Take arguments of type int.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/stdlib/tst-setcontext.c.diff?cvsroot=glibc&r1=1.7&r2=1.8

Comment 2 Roland McGrath 2006-03-03 11:52:44 UTC
I fixed the test to use standard behavior.