Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Jul 2010 15:09:16 +0300
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Garrett Cooper <yanegomi@gmail.com>
Cc:        hackers@freebsd.org
Subject:   Re: [PATCH] Catch errors with sigaddset(3) in sigaddset (sighold)
Message-ID:  <20100719120916.GX2381@deviant.kiev.zoral.com.ua>
In-Reply-To: <AANLkTik4fPb1WwHZzrFop_nIR6xxl_Ygw8Av3Z5cIb4Q@mail.gmail.com>
References:  <AANLkTik4fPb1WwHZzrFop_nIR6xxl_Ygw8Av3Z5cIb4Q@mail.gmail.com>

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

--hdMwqcnXK86+cyrC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Jul 18, 2010 at 10:46:25PM -0700, Garrett Cooper wrote:
>     sighold(3) doesn't determine whether or not the signal added is
> valid today (and sigprocmask doesn't verify that either). This fixes
> that.
> Thanks,
> -Garrett
>=20
> Index: sigcompat.c
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> --- sigcompat.c	(revision 210226)
> +++ sigcompat.c	(working copy)
> @@ -131,7 +131,8 @@
>  	sigset_t set;
>=20
>  	sigemptyset(&set);
> -	sigaddset(&set, sig);
> +	if (sigaddset(&set, sig) =3D=3D -1)
> +		return (-1);
>  	return (_sigprocmask(SIG_BLOCK, &set, NULL));
>  }

I added checks for failures of sig{add,del}set to the sigcompat.c,
and unified style to not assign intermediate error to local variable.

This is what I am going to commit shortly.

diff --git a/lib/libc/compat-43/sigcompat.c b/lib/libc/compat-43/sigcompat.c
index 6841eeb..199846f 100644
--- a/lib/libc/compat-43/sigcompat.c
+++ b/lib/libc/compat-43/sigcompat.c
@@ -112,16 +112,11 @@ int
 xsi_sigpause(int sig)
 {
 	sigset_t set;
-	int error;
=20
-	if (!_SIG_VALID(sig)) {
-		errno =3D EINVAL;
+	if (_sigprocmask(SIG_BLOCK, NULL, &set) =3D=3D -1)
+		return (-1);
+	if (sigdelset(&set, sig) =3D=3D -1)
 		return (-1);
-	}
-	error =3D _sigprocmask(SIG_BLOCK, NULL, &set);
-	if (error !=3D 0)
-		return (error);
-	sigdelset(&set, sig);
 	return (_sigsuspend(&set));
 }
=20
@@ -131,7 +126,8 @@ sighold(int sig)
 	sigset_t set;
=20
 	sigemptyset(&set);
-	sigaddset(&set, sig);
+	if (sigaddset(&set, sig) =3D=3D -1)
+		return (-1);
 	return (_sigprocmask(SIG_BLOCK, &set, NULL));
 }
=20
@@ -151,7 +147,8 @@ sigrelse(int sig)
 	sigset_t set;
=20
 	sigemptyset(&set);
-	sigaddset(&set, sig);
+	if (sigaddset(&set, sig) =3D=3D -1)
+		return (-1);
 	return (_sigprocmask(SIG_UNBLOCK, &set, NULL));
 }
=20
@@ -160,35 +157,30 @@ void
 {
 	sigset_t set, pset;
 	struct sigaction sa, psa;
-	int error;
=20
 	sigemptyset(&set);
-	sigaddset(&set, sig);
-	error =3D _sigprocmask(SIG_BLOCK, NULL, &pset);
-	if (error =3D=3D -1)
+	if (sigaddset(&set, sig) =3D=3D -1)
+		return (SIG_ERR);
+	if (_sigprocmask(SIG_BLOCK, NULL, &pset) =3D=3D -1)
 		return (SIG_ERR);
 	if ((__sighandler_t *)disp =3D=3D SIG_HOLD) {
-		error =3D _sigprocmask(SIG_BLOCK, &set, &pset);
-		if (error =3D=3D -1)
+		if (_sigprocmask(SIG_BLOCK, &set, &pset) =3D=3D -1)
 			return (SIG_ERR);
 		if (sigismember(&pset, sig))
 			return (SIG_HOLD);
 		else {
-			error =3D _sigaction(sig, NULL, &psa);
-			if (error =3D=3D -1)
+			if (_sigaction(sig, NULL, &psa) =3D=3D -1)
 				return (SIG_ERR);
 			return (psa.sa_handler);
 		}
 	} else {
-		error =3D _sigprocmask(SIG_UNBLOCK, &set, &pset);
-		if (error =3D=3D -1)
+		if (_sigprocmask(SIG_UNBLOCK, &set, &pset) =3D=3D -1)
 			return (SIG_ERR);
 	}
=20
 	bzero(&sa, sizeof(sa));
 	sa.sa_handler =3D disp;
-	error =3D _sigaction(sig, &sa, &psa);
-	if (error =3D=3D -1)
+	if (_sigaction(sig, &sa, &psa) =3D=3D -1)
 		return (SIG_ERR);
 	if (sigismember(&pset, sig))
 		return (SIG_HOLD);

--hdMwqcnXK86+cyrC
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (FreeBSD)

iEYEARECAAYFAkxEQGwACgkQC3+MBN1Mb4j7qgCePmu2WNnCAob9fpaYJSyx19w4
sAkAoJ7xYJ6eYUY20CGmMw6dzfg0Y1t3
=Xpz6
-----END PGP SIGNATURE-----

--hdMwqcnXK86+cyrC--



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