summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreric <eric@openbsd.org>2012-08-11 12:43:11 +0000
committereric <eric@openbsd.org>2012-08-11 12:43:11 +0000
commit26897f9d32a6a003829caa93f19748d1ab0140e5 (patch)
treedf32da45b7b08a652dde303f1cd4492a50029d4b
parentRemove dead code, from Sean Estabrooks. (diff)
downloadwireguard-openbsd-26897f9d32a6a003829caa93f19748d1ab0140e5.tar.xz
wireguard-openbsd-26897f9d32a6a003829caa93f19748d1ab0140e5.zip
make sure generated id is never 0.
ok gilles@
-rw-r--r--usr.sbin/smtpd/util.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 8fa0beff0c4..456170508cd 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.69 2012/08/08 08:50:42 eric Exp $ */
+/* $OpenBSD: util.c,v 1.70 2012/08/11 12:43:11 eric Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -846,9 +846,13 @@ sa_set_port(struct sockaddr *sa, int port)
u_int64_t
generate_uid(void)
{
- static u_int32_t id = 0;
+ static uint32_t id;
+ uint64_t uid;
- return ((uint64_t)(id++) << 32 | arc4random());
+ while ((uid = ((uint64_t)(id++) << 32 | arc4random())) == 0)
+ ;
+
+ return (uid);
}
void