bin/90580: wordexp(3) fails to check for EINTR
Florian Westphal
westphal at foo.fh-furtwangen.de
Sat Dec 17 14:40:03 PST 2005
>Number: 90580
>Category: bin
>Synopsis: wordexp(3) fails to check for EINTR
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Sat Dec 17 22:40:01 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator: Florian Westphal
>Release: FreeBSD 5.4-RELEASE-p6 i386
>Organization:
>Environment:
System: FreeBSD abraxis.ask.fh-furtwangen.de 5.4-RELEASE-p6 FreeBSD 5.4-RELEASE-p6 #12: Wed Aug 17 09:26:21 CEST 2005 root at abraxis.ask.fh-furtwangen.de:/usr/obj/usr/src/sys/ABRAXIS i386
AMD k6/233 mhz, 32meg ram
>Description:
wordexp() fails if a syscall fails; no check for errno == EINTR is performed.
Applications that install signal handlers for SIGCHLD will be in a race with
wordexp. The program below often fails on my box.
>How-To-Repeat:
/* This sample program MAY work or not work, depending on timing */
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <wordexp.h>
static void handler(int x) { (void)x; }
int main(void)
{
struct sigaction sa;
const char * expand = "*";
wordexp_t p;
int ret;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sa.sa_handler = handler;
if (sigaction(SIGCHLD,&sa, NULL) != 0)
return 111;
errno = 0;
ret = wordexp(expand, &p, WRDE_SHOWERR|WRDE_UNDEF);
if (ret == 0) {
unsigned int i;
char **w = p.we_wordv;
for (i=0; i<p.we_wordc; i++)
printf("got token: \"%s\"\n", w[i]);
wordfree(&p);
} else {
printf("wordexp failed, ret %d, err %s\n:", ret, strerror(errno));
}
return 0;
}
>Fix:
Have wordexp() check for errno == EINTR
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list