Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 31 May 2015 08:20:16 +0000
From:      "rodrigc (Craig Rodrigues)" <phabric-noreply@FreeBSD.org>
To:        freebsd-toolchain@freebsd.org
Subject:   [Differential] [Request, 22 lines] D2690: In ypbind, eliminate error: dereferencing type-punned pointer will break strict-aliasing rules
Message-ID:  <differential-rev-PHID-DREV-5wjobtbl22co3qb2erjl-req@FreeBSD.org>

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

--b1_8f01fff7f42147fd699240cbe1b1b6f3
Content-Type: text/plain; charset = "utf-8"
Content-Transfer-Encoding: 8bit

rodrigc created this revision.
rodrigc added reviewers: araujo, bapt, emaste, dim.
rodrigc added a subscriber: freebsd-toolchain.
rodrigc set the repository for this revision to rS FreeBSD src repository.
Herald added a subscriber: imp.

REVISION SUMMARY
  Without this fix, compiling ypbind with gcc 4.9 will give warnings such as this:
  
  ```
  /opt2/branches/head/usr.sbin/ypbind/ypbind.c: In function 'rpc_received':
  /opt2/branches/head/usr.sbin/ypbind/ypbind.c:948:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(u_int32_t *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr = raddrp->sin_addr.s_addr;
    ^
  ```

REPOSITORY
  rS FreeBSD src repository

REVISION DETAIL
  https://reviews.freebsd.org/D2690

AFFECTED FILES
  usr.sbin/ypbind/ypbind.c

CHANGE DETAILS
  diff --git a/usr.sbin/ypbind/ypbind.c b/usr.sbin/ypbind/ypbind.c
  --- a/usr.sbin/ypbind/ypbind.c
  +++ b/usr.sbin/ypbind/ypbind.c
  @@ -225,10 +225,10 @@
   
   	res.ypbind_status = YPBIND_SUCC_VAL;
   	res.ypbind_resp_u.ypbind_error = 0; /* Success */
  -	*(u_int32_t *)&res.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr =
  -		ypdb->dom_server_addr.sin_addr.s_addr;
  -	*(u_short *)&res.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port =
  -		ypdb->dom_server_addr.sin_port;
  +	memcpy(&res.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr,
  +	    &ypdb->dom_server_addr.sin_addr.s_addr, sizeof(u_int32_t));
  +	memcpy(&res.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port,
  +	    &ypdb->dom_server_addr.sin_port, sizeof(u_short));
   	/*printf("domain %s at %s/%d\n", ypdb->dom_domain,
   		inet_ntoa(ypdb->dom_server_addr.sin_addr),
   		ntohs(ypdb->dom_server_addr.sin_port));*/
  @@ -275,8 +275,12 @@
   
   	bzero(&bindsin, sizeof bindsin);
   	bindsin.sin_family = AF_INET;
  -	bindsin.sin_addr.s_addr = *(u_int32_t *)argp->ypsetdom_binding.ypbind_binding_addr;
  -	bindsin.sin_port = *(u_short *)argp->ypsetdom_binding.ypbind_binding_port;
  +	memcpy(&bindsin.sin_addr.s_addr,
  +	    &argp->ypsetdom_binding.ypbind_binding_addr,
  +	    sizeof(u_int32_t));
  +	memcpy(&bindsin.sin_port,
  +	    &argp->ypsetdom_binding.ypbind_binding_port,
  +	    sizeof(u_short));
   	rpc_received(argp->ypsetdom_domain, &bindsin, 1);
   
   	return((void *) &result);
  @@ -945,8 +949,10 @@
   
   	bzero(&ybr, sizeof ybr);
   	ybr.ypbind_status = YPBIND_SUCC_VAL;
  -	*(u_int32_t *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr = raddrp->sin_addr.s_addr;
  -	*(u_short *)&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port = raddrp->sin_port;
  +	memcpy(ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr,
  +	    &raddrp->sin_addr.s_addr, sizeof(u_int32_t));
  +	memcpy(&ybr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_port,
  +	    &raddrp->sin_port, sizeof(u_short));
   
   	if (writev(ypdb->dom_lockfd, iov, 2) != iov[0].iov_len + iov[1].iov_len) {
   		syslog(LOG_WARNING, "write: %m");

EMAIL PREFERENCES
  https://reviews.freebsd.org/settings/panel/emailpreferences/

To: rodrigc, araujo, bapt, emaste, dim
Cc: imp, freebsd-toolchain

--b1_8f01fff7f42147fd699240cbe1b1b6f3
Content-Type: text/x-patch; charset=utf-8; name="D2690.5826.patch"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="D2690.5826.patch"

ZGlmZiAtLWdpdCBhL3Vzci5zYmluL3lwYmluZC95cGJpbmQuYyBiL3Vzci5zYmluL3lwYmluZC95
cGJpbmQuYwotLS0gYS91c3Iuc2Jpbi95cGJpbmQveXBiaW5kLmMKKysrIGIvdXNyLnNiaW4veXBi
aW5kL3lwYmluZC5jCkBAIC0yMjUsMTAgKzIyNSwxMCBAQAogCiAJcmVzLnlwYmluZF9zdGF0dXMg
PSBZUEJJTkRfU1VDQ19WQUw7CiAJcmVzLnlwYmluZF9yZXNwX3UueXBiaW5kX2Vycm9yID0gMDsg
LyogU3VjY2VzcyAqLwotCSoodV9pbnQzMl90ICopJnJlcy55cGJpbmRfcmVzcF91LnlwYmluZF9i
aW5kaW5mby55cGJpbmRfYmluZGluZ19hZGRyID0KLQkJeXBkYi0+ZG9tX3NlcnZlcl9hZGRyLnNp
bl9hZGRyLnNfYWRkcjsKLQkqKHVfc2hvcnQgKikmcmVzLnlwYmluZF9yZXNwX3UueXBiaW5kX2Jp
bmRpbmZvLnlwYmluZF9iaW5kaW5nX3BvcnQgPQotCQl5cGRiLT5kb21fc2VydmVyX2FkZHIuc2lu
X3BvcnQ7CisJbWVtY3B5KCZyZXMueXBiaW5kX3Jlc3BfdS55cGJpbmRfYmluZGluZm8ueXBiaW5k
X2JpbmRpbmdfYWRkciwKKwkgICAgJnlwZGItPmRvbV9zZXJ2ZXJfYWRkci5zaW5fYWRkci5zX2Fk
ZHIsIHNpemVvZih1X2ludDMyX3QpKTsKKwltZW1jcHkoJnJlcy55cGJpbmRfcmVzcF91LnlwYmlu
ZF9iaW5kaW5mby55cGJpbmRfYmluZGluZ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c3RhdHVzID0g
WVBCSU5EX1NVQ0NfVkFMOwotCSoodV9pbnQzMl90ICopJnlici55cGJpbmRfcmVzcF91LnlwYmlu
ZF9iaW5kaW5mby55cGJpbmRfYmluZGluZ19hZGRyID0gcmFkZHJwLT5zaW5fYWRkci5zX2FkZHI7
Ci0JKih1X3Nob3J0ICopJnlici55cGJpbmRfcmVzcF91LnlwYmluZF9iaW5kaW5mby55cGJpbmRf
YmluZGluZ19wb3J0ID0gcmFkZHJwLT5zaW5fcG9ydDsKKwltZW1jcHkoeWJyLnlwYmluZF9yZXNw
X3UueXBiaW5kX2JpbmRpbmZvLnlwYmluZF9iaW5kaW5nX2FkZHIsCisJICAgICZyYWRkcnAtPnNp
bl9hZGRyLnNfYWRkciwgc2l6ZW9mKHVfaW50MzJfdCkpOworCW1lbWNweSgmeWJyLnlwYmluZF9y
ZXNwX3UueXBiaW5kX2JpbmRpbmZvLnlwYmluZF9iaW5kaW5nX3BvcnQsCisJICAgICZyYWRkcnAt
PnNpbl9wb3J0LCBzaXplb2YodV9zaG9ydCkpOwogCiAJaWYgKHdyaXRldih5cGRiLT5kb21fbG9j
a2ZkLCBpb3YsIDIpICE9IGlvdlswXS5pb3ZfbGVuICsgaW92WzFdLmlvdl9sZW4pIHsKIAkJc3lz
bG9nKExPR19XQVJOSU5HLCAid3JpdGU6ICVtIik7Cgo=


--b1_8f01fff7f42147fd699240cbe1b1b6f3--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?differential-rev-PHID-DREV-5wjobtbl22co3qb2erjl-req>