All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] creat07: Drop basename() function call from read-only variable
@ 2012-02-23  9:56 Markos Chandras
  2012-02-23 15:38 ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Markos Chandras @ 2012-02-23  9:56 UTC (permalink / raw)
  To: ltp-list

test_app is a read-only variable because it is defined as a preprocessor macro.
Using basename() on this variable, it will most certainly lead to a segmentation
fault in uClibc code. Moreover, there is no need to use basename() at all since
the test_app variable is a single string and it does not contain any leading
paths.

Quote from uClibc's include/libgen.h header:

"Return final component of PATH.
	This is the weird XPG version of this function.  It sometimes will
	modify its argument.  Therefore we normally use the GNU version (in
	<string.h>) and only if this header is included make the XPG
	version available under the real name.

	extern char *__xpg_basename (char *__path) __THROW;
	#define basename        __xpg_basename"

Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
---
 testcases/kernel/syscalls/creat/creat07.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/creat/creat07.c b/testcases/kernel/syscalls/creat/creat07.c
index 3bb1288..294f998 100644
--- a/testcases/kernel/syscalls/creat/creat07.c
+++ b/testcases/kernel/syscalls/creat/creat07.c
@@ -91,7 +91,7 @@ int main(int ac, char **av)
 
 		if (pid == 0) {
 			char *av[2];
-			av[0] = basename(test_app);
+			av[0] = test_app;
 			av[1] = NULL;
 			(void)execve(test_app, av, NULL);
 			perror("execve failed");
@@ -147,7 +147,7 @@ void setup(char *app)
 			tst_brkm(TBROK|TERRNO, NULL, "getcwd failed");
 
 		snprintf(test_path, sizeof(test_path), "%s/%s",
-		    pwd, basename(test_app));
+		    pwd, test_app);
 
 		free(pwd);
 	}
-- 
1.7.1



------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] creat07: Drop basename() function call from read-only variable
  2012-02-23  9:56 [LTP] [PATCH] creat07: Drop basename() function call from read-only variable Markos Chandras
@ 2012-02-23 15:38 ` Cyril Hrubis
       [not found]   ` <4F465F43.8010503@imgtec.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2012-02-23 15:38 UTC (permalink / raw)
  To: Markos Chandras; +Cc: ltp-list

Hi!
> test_app is a read-only variable because it is defined as a preprocessor macro.
> Using basename() on this variable, it will most certainly lead to a segmentation
> fault in uClibc code. Moreover, there is no need to use basename() at all since
> the test_app variable is a single string and it does not contain any leading
> paths.
> 
> Quote from uClibc's include/libgen.h header:
> 
> "Return final component of PATH.
> 	This is the weird XPG version of this function.  It sometimes will
> 	modify its argument.  Therefore we normally use the GNU version (in
> 	<string.h>) and only if this header is included make the XPG
> 	version available under the real name.
> 
> 	extern char *__xpg_basename (char *__path) __THROW;
> 	#define basename        __xpg_basename"

Well in glibc you get version that is not reentrant but doesn't modify
the source string when _GNU_SOURCE is defined (which is defined in
creat07.c), so this may be bug in uClibc compatibility.

And I think that there is no reason to segfault when the argument
doesn't need to be modified, which should be the case here. Or did the
segfault occured in your enviroment?

However commit this as the call is useless here.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH] creat07: Drop basename() function call from read-only variable
       [not found]   ` <4F465F43.8010503@imgtec.com>
@ 2012-02-23 15:56     ` Cyril Hrubis
  0 siblings, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2012-02-23 15:56 UTC (permalink / raw)
  To: Markos Chandras; +Cc: ltp-list

Hi!
> > Well in glibc you get version that is not reentrant but doesn't modify
> > the source string when _GNU_SOURCE is defined (which is defined in
> > creat07.c), so this may be bug in uClibc compatibility.
> > 
> > And I think that there is no reason to segfault when the argument
> > doesn't need to be modified, which should be the case here. Or did the
> > segfault occured in your enviroment?
> 
> 
> It segfaults if it modifies the argument because the argument is
> read-only. I don't remember when this function modifies the argument but
> it certainly is a bit dangerous to use a read-only variable when this
> function has known "weird" behaviour

Okay, commited.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-23 15:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-23  9:56 [LTP] [PATCH] creat07: Drop basename() function call from read-only variable Markos Chandras
2012-02-23 15:38 ` Cyril Hrubis
     [not found]   ` <4F465F43.8010503@imgtec.com>
2012-02-23 15:56     ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.