DragonFlyBSD bugtracker: Issueshttps://bugs.dragonflybsd.org/https://bugs.dragonflybsd.org/favicon.ico?16293952082017-12-13T06:20:02ZDragonFlyBSD bugtracker
Redmine DragonFlyBSD - Submit #3112 (Closed): Avoid undefined shifts in bit selector loophttps://bugs.dragonflybsd.org/issues/31122017-12-13T06:20:02Zmmcc
<p>Hi guys.</p>
<p>I fixed this issue in OpenBSD a while back, but I figured I should check and<br />inform the rest of the BSDs.</p>
<p>Shifting into or out of an int's sign bit is undefined, and this loop<br />deterministically and intentionally does both. The following change<br />was applied to OpenBSD and (IIRC) NetBSD.</p>
<p>Thanks for your time,<br />Michael McConville</p>
<p>diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c<br />index 8145d9e052..5930a462f2 100644<br />--- a/sbin/dhclient/dhclient.c<br />+++ b/sbin/dhclient/dhclient.c<br /><code>@ -108,7 +108,7 </code>@ int<br />findproto(char *cp, int n)
{<br /> struct sockaddr *sa;<br />- int i;<br />+ unsigned int i;</p>
<pre><code>if (n == 0)<br /> return -1;</code></pre>