pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/devel/libusb1 libusb1: patch some undefined behaviour, ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/165b102ac5fa
branches:  trunk
changeset: 337488:165b102ac5fa
user:      maya <maya%pkgsrc.org@localhost>
date:      Tue Aug 06 08:50:28 2019 +0000

description:
libusb1: patch some undefined behaviour, disable strict aliasing, change
-O2 to -O1 when building with clang.

This isn't in a separate hacks.mk file because I think that hides the
problem too much, it's an issue with the code in the package, not with
the compiler's choices.

Fixes functionality when built with clang.

>From Shingo Nishioka in PR pkg/54441.

diffstat:

 devel/libusb1/Makefile         |  10 +++++++++-
 devel/libusb1/distinfo         |   3 ++-
 devel/libusb1/patches/patch-ub |  36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 2 deletions(-)

diffs (81 lines):

diff -r a5c31801e30e -r 165b102ac5fa devel/libusb1/Makefile
--- a/devel/libusb1/Makefile    Tue Aug 06 07:52:03 2019 +0000
+++ b/devel/libusb1/Makefile    Tue Aug 06 08:50:28 2019 +0000
@@ -1,7 +1,8 @@
-# $NetBSD: Makefile,v 1.18 2019/06/22 11:30:11 nia Exp $
+# $NetBSD: Makefile,v 1.19 2019/08/06 08:50:28 maya Exp $
 
 DISTNAME=      libusb-1.0.22
 PKGNAME=       ${DISTNAME:S/libusb/libusb1/}
+PKGREVISION=   1
 CATEGORIES=    devel
 MASTER_SITES=  ${MASTER_SITE_SOURCEFORGE:=libusb/}
 EXTRACT_SUFX=  .tar.bz2
@@ -20,6 +21,13 @@
 USE_TOOLS+=    pkg-config
 MAKE_JOBS_SAFE=            no
 
+.include "../../mk/compiler.mk"
+.if !empty(PKGSRC_COMPILER:Mclang)
+# Uses undefined behaviour
+BUILDLINK_TRANSFORM+=  opt:-O2:-O1
+CFLAGS+=               -fno-strict-aliasing
+.endif
+
 PKGCONFIG_OVERRIDE+=   libusb-1.0.pc.in
 
 # systemd dependency
diff -r a5c31801e30e -r 165b102ac5fa devel/libusb1/distinfo
--- a/devel/libusb1/distinfo    Tue Aug 06 07:52:03 2019 +0000
+++ b/devel/libusb1/distinfo    Tue Aug 06 08:50:28 2019 +0000
@@ -1,4 +1,4 @@
-$NetBSD: distinfo,v 1.10 2019/06/21 16:58:23 sjmulder Exp $
+$NetBSD: distinfo,v 1.11 2019/08/06 08:50:28 maya Exp $
 
 SHA1 (libusb-1.0.22.tar.bz2) = 10116aa265aac4273a0c894faa089370262ec0dc
 RMD160 (libusb-1.0.22.tar.bz2) = 59b800abb0b4c088dbee950fa67bb31240b8a134
@@ -7,3 +7,4 @@
 SHA1 (patch-configure) = 2776ff354ea8f17663a9a5330f6fe990af27d8fe
 SHA1 (patch-configure.ac) = 9344b3d6439348164410d1b2071cf14c3f388354
 SHA1 (patch-libusb_os_sunos__usb.c) = 4896e497d451487a09b3be9ad74f72595a441086
+SHA1 (patch-ub) = 14bffca93ec8445cbfccb613dfda92f652b0ceb0
diff -r a5c31801e30e -r 165b102ac5fa devel/libusb1/patches/patch-ub
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/libusb1/patches/patch-ub    Tue Aug 06 08:50:28 2019 +0000
@@ -0,0 +1,36 @@
+$NetBSD: patch-ub,v 1.1 2019/08/06 08:50:28 maya Exp $
+
+Avoid undefined behaviour that breaks clang
+
+--- 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;
+



Home | Main Index | Thread Index | Old Index