bin/90580: wordexp(3) fails to check for EINTR

Florian Westphal westphal at
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
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Dec 17 22:40:01 GMT 2005
>Originator:     Florian Westphal
>Release:        FreeBSD 5.4-RELEASE-p6 i386
System: FreeBSD 5.4-RELEASE-p6 FreeBSD 5.4-RELEASE-p6 #12: Wed Aug 17 09:26:21 CEST 2005 root at i386

	AMD k6/233 mhz, 32meg ram
	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.
/* 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;
        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]);

        } else {
		printf("wordexp failed, ret %d, err %s\n:", ret, strerror(errno));
	return 0;
	Have wordexp() check for errno == EINTR


More information about the freebsd-bugs mailing list