Bug 1125 - crash in execvp()
Summary: crash in execvp()
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.3.5
: P2 normal
Target Milestone: ---
Assignee: GOTO Masanori
URL:
Keywords:
Depends on:
Blocks: libc236
  Show dependency treegraph
 
Reported: 2005-07-24 18:44 UTC by Serge Belyshev
Modified: 2019-04-10 10:45 UTC (History)
2 users (show)

See Also:
Host: x86_64-*-linux-gnu
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Serge Belyshev 2005-07-24 18:44:35 UTC
This small program crashes glibc in execvp():

---------------------------------------------------
#include <unistd.h>

extern char **environ;
static char *empty[] = { 0 };

int main (void)
{
  environ = empty;
  execvp ("nothing ", empty);
  return 0;
}
---------------------------------------------------

$ ./a.out 
*** glibc detected *** free(): invalid pointer: 0x0000000000501016 ***
Aborted (core dumped)
$ 

similar effect can be achieved by executing "env -i nonexistent_program".

the problem seems to be here, posix/execvp.c:121:

      char *p = path;
      do
	{
	  char *startp;

	  path = p;                      // it changes 'path' inside loop
	  p = __strchrnul (path, ':');

          ...

	}
      while (*p++ != '\0');
      ...

      if (path_malloc)
	free (path);                     // and then frees it.
Comment 1 GOTO Masanori 2005-07-29 03:55:12 UTC
Fixed in the latest cvs.
Comment 2 Sourceware Commits 2005-10-17 09:05:21 UTC
Subject: Bug 1125

CVSROOT:	/cvs/glibc
Module name:	libc
Branch: 	glibc-2_3-branch
Changes by:	roland@sources.redhat.com	2005-10-17 09:05:18

Modified files:
	posix          : execvp.c 

Log message:
	2005-07-24  Jakub Jelinek  <jakub@redhat.com>
	
	[BZ #1125]
	* posix/execvp.c (execvp): Change path_malloc to
	char *, free that pointer on failure.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/posix/execvp.c.diff?cvsroot=glibc&only_with_tag=glibc-2_3-branch&r1=1.21.2.3&r2=1.21.2.4

Comment 3 Sourceware Commits 2005-10-17 09:05:23 UTC
Subject: Bug 1125

CVSROOT:	/cvs/glibc
Module name:	libc
Branch: 	glibc-2_3-branch
Changes by:	roland@sources.redhat.com	2005-10-17 09:05:20

Modified files:
	posix          : Makefile 
Added files:
	posix          : tst-execvp4.c 

Log message:
	2005-07-24  Ulrich Drepper  <drepper@redhat.com>
	
	[BZ #1125]
	* posix/Makefile (tests): Add tst-execvp4.
	* posix/tst-execvp4.c: New file.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/posix/tst-execvp4.c.diff?cvsroot=glibc&only_with_tag=glibc-2_3-branch&r1=NONE&r2=1.1.4.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/posix/Makefile.diff?cvsroot=glibc&only_with_tag=glibc-2_3-branch&r1=1.179.2.3&r2=1.179.2.4

Comment 4 Florian Weimer 2019-04-10 10:45:54 UTC
Flagging as security-; no apparent application impact.