Module Name:    src
Committed By:   kre
Date:           Sat Jul 28 13:51:26 UTC 2018

Modified Files:
        src/external/bsd/cron/dist: entry.c

Log Message:
Fix from Michael Kaufmann in PR bin/53476

Do modulus using unsigned arith, and then convert the result to
int, rather than converting the arc4random() result to int (which
might be negative) and performing a modulus on that (with a
potentially negative answer).


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/external/bsd/cron/dist/entry.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/cron/dist/entry.c
diff -u src/external/bsd/cron/dist/entry.c:1.8 src/external/bsd/cron/dist/entry.c:1.9
--- src/external/bsd/cron/dist/entry.c:1.8	Thu Jun 14 22:04:28 2018
+++ src/external/bsd/cron/dist/entry.c	Sat Jul 28 13:51:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: entry.c,v 1.8 2018/06/14 22:04:28 christos Exp $	*/
+/*	$NetBSD: entry.c,v 1.9 2018/07/28 13:51:26 kre Exp $	*/
 
 /*
  * Copyright 1988,1990,1993,1994 by Paul Vixie
@@ -26,7 +26,7 @@
 #if 0
 static char rcsid[] = "Id: entry.c,v 1.17 2004/01/23 18:56:42 vixie Exp";
 #else
-__RCSID("$NetBSD: entry.c,v 1.8 2018/06/14 22:04:28 christos Exp $");
+__RCSID("$NetBSD: entry.c,v 1.9 2018/07/28 13:51:26 kre Exp $");
 #endif
 #endif
 
@@ -471,7 +471,7 @@ random_with_range(int low, int high)
 	if (low >= high)
 		return low;
 	else
-		return (int)arc4random() % (high - low + 1) + low;
+		return (int)(arc4random() % (unsigned)((high - low + 1) + low));
 }
 
 static int

Reply via email to