dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Felix Janda <felix.janda@posteo.de>
To: dri-devel@lists.freedesktop.org
Subject: [PATCH libdrm] Fix strict aliasing violation in drmHandleEvent
Date: Wed, 5 Oct 2016 22:55:06 -0400	[thread overview]
Message-ID: <20161006025506.GA8538@nyan> (raw)

&buffer[i], e and vblank have been pointers of different types but
refering to the same memory location, thus breaking the strict
aliasing rules.

Fix this by working exclusively with pointers to char.

Signed-off-by: Felix Janda <felix.janda@posteo.de>
---
 xf86drmMode.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/xf86drmMode.c b/xf86drmMode.c
index 228c6e4..cc776c1 100644
--- a/xf86drmMode.c
+++ b/xf86drmMode.c
@@ -885,10 +885,10 @@ int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size,
 
 int drmHandleEvent(int fd, drmEventContextPtr evctx)
 {
-	char buffer[1024];
-	int len, i;
-	struct drm_event *e;
-	struct drm_event_vblank *vblank;
+	char buffer[1024], *p;
+	int len;
+	struct drm_event e;
+	struct drm_event_vblank vblank;
 
 	/* The DRM read semantics guarantees that we always get only
 	 * complete events. */
@@ -896,39 +896,39 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx)
 	len = read(fd, buffer, sizeof buffer);
 	if (len == 0)
 		return 0;
-	if (len < (int)sizeof *e)
+	if (len < (int)sizeof e)
 		return -1;
 
-	i = 0;
-	while (i < len) {
-		e = (struct drm_event *) &buffer[i];
-		switch (e->type) {
+	p = buffer;
+	while (p < buffer + len) {
+		e = *(struct drm_event *) p;
+		switch (e.type) {
 		case DRM_EVENT_VBLANK:
 			if (evctx->version < 1 ||
 			    evctx->vblank_handler == NULL)
 				break;
-			vblank = (struct drm_event_vblank *) e;
+			vblank = *(struct drm_event_vblank *) p;
 			evctx->vblank_handler(fd,
-					      vblank->sequence,
-					      vblank->tv_sec,
-					      vblank->tv_usec,
-					      U642VOID (vblank->user_data));
+					      vblank.sequence,
+					      vblank.tv_sec,
+					      vblank.tv_usec,
+					      U642VOID (vblank.user_data));
 			break;
 		case DRM_EVENT_FLIP_COMPLETE:
 			if (evctx->version < 2 ||
 			    evctx->page_flip_handler == NULL)
 				break;
-			vblank = (struct drm_event_vblank *) e;
+			vblank = *(struct drm_event_vblank *) p;
 			evctx->page_flip_handler(fd,
-						 vblank->sequence,
-						 vblank->tv_sec,
-						 vblank->tv_usec,
-						 U642VOID (vblank->user_data));
+						 vblank.sequence,
+						 vblank.tv_sec,
+						 vblank.tv_usec,
+						 U642VOID (vblank.user_data));
 			break;
 		default:
 			break;
 		}
-		i += e->length;
+		p += e.length;
 	}
 
 	return 0;
-- 
2.7.3
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

                 reply	other threads:[~2016-10-06  3:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161006025506.GA8538@nyan \
    --to=felix.janda@posteo.de \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).