Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 Feb 2005 23:45:18 GMT
From:      Gavin Atkinson <gavin.atkinson@ury.york.ac.uk>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/78170: [patch] Fix signal handler in bootpd
Message-ID:  <200502272345.j1RNjINn069708@buffy.york.ac.uk>
Resent-Message-ID: <200502272350.j1RNoCO1077982@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         78170
>Category:       bin
>Synopsis:       [patch] Fix signal handler in bootpd
>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:   Sun Feb 27 23:50:12 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Gavin Atkinson
>Release:        FreeBSD 5.3-STABLE i386
>Organization:
>Environment:
System: FreeBSD buffy.york.ac.uk 5.3-STABLE FreeBSD 5.3-STABLE #0: Sat Feb 12 20:42:16 GMT 2005 root@buffy.york.ac.uk:/usr/obj/usr/src/sys/BUFFY i386

>Description:

	I've been inspired by the talk given by Henning Brauer given at
the UKUUG Winter 2005 on writing safe signal handlers, and have set about
fixing some of them in the FreeBSD source tree.

Slides for this (well, an almost identical) presentation are at
http://www.openbsd.org/papers/opencon04/index.html

>How-To-Repeat:
	N/A
>Fix:

The fix involves using a data type that can be used atomically
(sig_atomic_t), and saving errno over calls to other system calls.

--- bootpd-sigs.patch begins here ---
Index: src/libexec/bootpd/bootpd.c
===================================================================
RCS file: /usr/cvs/src/libexec/bootpd/bootpd.c,v
retrieving revision 1.23
diff -u -r1.23 bootpd.c
--- src/libexec/bootpd/bootpd.c	14 Feb 2005 17:42:56 -0000	1.23
+++ src/libexec/bootpd/bootpd.c	27 Feb 2005 23:03:25 -0000
@@ -158,8 +158,8 @@
 static char default_hostname[MAXHOSTNAMELEN];
 
 /* Flags set by signal catcher. */
-PRIVATE int do_readtab = 0;
-PRIVATE int do_dumptab = 0;
+PRIVATE volatile sig_atomic_t do_readtab = 0;
+PRIVATE volatile sig_atomic_t do_dumptab = 0;
 
 /*
  * Globals below are associated with the bootp database file (bootptab).
@@ -598,6 +598,10 @@
 catcher(sig)
 	int sig;
 {
+#if	!defined(SA_NOCLDSTOP) && defined(SYSV)
+	int save_errno = errno;
+#endif
+
 	if (sig == SIGHUP)
 		do_readtab = 1;
 	if (sig == SIGUSR1)
@@ -605,6 +609,7 @@
 #if	!defined(SA_NOCLDSTOP) && defined(SYSV)
 	/* For older "System V" derivatives with no sigaction(). */
 	signal(sig, catcher);
+	errno = save_errno;
 #endif
 }
 
--- bootpd-sigs.patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200502272345.j1RNjINn069708>