Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Oct 2016 17:03:22 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r306708 - head/lib/libc/stdlib
Message-ID:  <201610051703.u95H3MRS016637@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: emaste
Date: Wed Oct  5 17:03:22 2016
New Revision: 306708
URL: https://svnweb.freebsd.org/changeset/base/306708

Log:
  abort in srandomdev if kern.arandom sysctl fails
  
  The sysctl cannot fail. If it does fail on some FreeBSD derivative or
  after some future change, just abort() so that the problem will be found
  and fixed.
  
  While abort() is not normally suitable for a library, it makes sense
  here.
  
  This is akin to r306636 for arc4random.
  
  Reviewed by:	ed
  MFC after:	2 weeks
  Sponsored by:	The FreeBSD Foundation
  Differential Revision:	https://reviews.freebsd.org/D8077

Modified:
  head/lib/libc/stdlib/random.c

Modified: head/lib/libc/stdlib/random.c
==============================================================================
--- head/lib/libc/stdlib/random.c	Wed Oct  5 16:23:02 2016	(r306707)
+++ head/lib/libc/stdlib/random.c	Wed Oct  5 17:03:22 2016	(r306708)
@@ -270,16 +270,17 @@ void
 srandomdev(void)
 {
 	int mib[2];
-	size_t len;
+	size_t expected, len;
 
 	if (rand_type == TYPE_0)
-		len = sizeof(state[0]);
+		expected = len = sizeof(state[0]);
 	else
-		len = rand_deg * sizeof(state[0]);
+		expected = len = rand_deg * sizeof(state[0]);
 
 	mib[0] = CTL_KERN;
 	mib[1] = KERN_ARND;
-	sysctl(mib, 2, state, &len, NULL, 0);
+	if (sysctl(mib, 2, state, &len, NULL, 0) == -1 || len != expected)
+		abort();
 
 	if (rand_type != TYPE_0) {
 		fptr = &state[rand_sep];



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