pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pkg/54441: devel/liubusb undefined behaviour



>Number:         54441
>Category:       pkg
>Synopsis:       devel/liubusb undefined behaviour
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 06 03:25:00 +0000 2019
>Originator:     Shingo Nishioka
>Release:        Tpkgsrc-2019Q2
>Organization:
>Environment:
8.1_STABLE
>Description:
As func. usb_parse_descriptor contains some undefined behavior code, which violates strict aliasing rules, when compiled with clang -O2, the library does not work properly.
>How-To-Repeat:
Add follwing lines to /etc/mk.conf and rebuild the library

MKGCC=no
MKLLVM=yes
HAVE_LLVM=yes
PKGSRC_COMPILER=clang
CLANGBASE=/usr

>Fix:
One of the followings will do:

1. apply following patch

--- libusb/descriptor.c.orig	2019-08-02 09:59:25.784968424 +0900
+++ libusb/descriptor.c	2019-08-02 09:59:44.009134412 +0900
@@ -54,7 +54,9 @@
 	for (cp = descriptor; *cp; cp++) {
 		switch (*cp) {
 			case 'b':	/* 8-bit byte */
-				*dp++ = *sp++;
+				memcpy(dp, sp, 1);
+				dp += 1;
+				sp += 1;
 				break;
 			case 'w':	/* 16-bit word, convert from little endian to CPU */
 				dp += ((uintptr_t)dp & 1);	/* Align to word boundary */
@@ -63,7 +65,7 @@
 					memcpy(dp, sp, 2);
 				} else {
 					w = (sp[1] << 8) | sp[0];
-					*((uint16_t *)dp) = w;
+					memcpy(dp, &w, 4);
 				}
 				sp += 2;
 				dp += 2;
@@ -76,7 +78,7 @@
 				} else {
 					d = (sp[3] << 24) | (sp[2] << 16) |
 						(sp[1] << 8) | sp[0];
-					*((uint32_t *)dp) = d;
+					memcpy(dp, &d, 4);
 				}
 				sp += 4;
 				dp += 4;



2. disable -O2 level optimization (-O 1 will do)

3. allow strict aliasing rules violation (-fno-strict-aliasing)


Home | Main Index | Thread Index | Old Index