commit d9d930b903c7d5f20ab2fc23e995597f0bfea415 Author: overweight <5324761+overweight@user.noreply.gitee.com> Date: Mon Sep 30 10:57:33 2019 -0400 Package init diff --git a/6000-linux-Set-number-of-devices-to-0-in-case-of-error.patch b/6000-linux-Set-number-of-devices-to-0-in-case-of-error.patch new file mode 100644 index 0000000..e2a3600 --- /dev/null +++ b/6000-linux-Set-number-of-devices-to-0-in-case-of-error.patch @@ -0,0 +1,35 @@ +From 44f3dd08f99ba67e967980daaea2b800c68e2659 Mon Sep 17 00:00:00 2001 +From: Olivier Fourdan +Date: Wed, 24 Oct 2018 10:11:49 +0200 +Subject: [PATCH 1/3] linux: Set number of devices to 0 in case of error + +pci_sys is a global variable which is populated on init, and in case of +error reading sysfs on Linux, the devices are NULL, but the number of +devices is left unchanged. + +As a result, we may crash in `pci_device_next()` which relies on the +number of devices. + +To fix the issue, simply reset the number of devices to zero in case of +error so we don't try to access indices of a NULL array later on. + +Signed-off-by: Olivier Fourdan +--- + src/linux_sysfs.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/linux_sysfs.c b/src/linux_sysfs.c +index a8bc2e1..e74ad72 100644 +--- a/src/linux_sysfs.c ++++ b/src/linux_sysfs.c +@@ -264,6 +264,7 @@ populate_entries( struct pci_system * p ) + if (err) { + free(p->devices); + p->devices = NULL; ++ p->num_devices = 0; + } + + return err; +-- +2.19.1 + diff --git a/libpciaccess-0.14.tar.bz2 b/libpciaccess-0.14.tar.bz2 new file mode 100644 index 0000000..c0ec494 Binary files /dev/null and b/libpciaccess-0.14.tar.bz2 differ diff --git a/libpciaccess-rom-size.patch b/libpciaccess-rom-size.patch new file mode 100644 index 0000000..baf8026 --- /dev/null +++ b/libpciaccess-rom-size.patch @@ -0,0 +1,73 @@ +diff --git a/src/linux_sysfs.c b/src/linux_sysfs.c +index 8c3cf67..2ea78c1 100644 +--- a/src/linux_sysfs.c ++++ b/src/linux_sysfs.c +@@ -227,6 +227,7 @@ pci_device_linux_sysfs_probe( struct pci_device * dev ) + pciaddr_t bytes; + unsigned i; + int err; ++ struct stat st; + + + err = pci_device_linux_sysfs_read( dev, config, 0, 256, & bytes ); +@@ -293,11 +294,28 @@ pci_device_linux_sysfs_probe( struct pci_device * dev ) + flags = strtoull( next, & next, 16 ); + if ( low_addr != 0 ) { + priv->rom_base = low_addr; +- dev->rom_size = (high_addr - low_addr) + 1; + } + } + } + ++ snprintf( name, 255, "%s/%04x:%02x:%02x.%1u/rom", ++ SYS_BUS_PCI, ++ dev->domain, ++ dev->bus, ++ dev->dev, ++ dev->func ); ++ ++ fd = open( name, O_RDWR ); ++ if ( fd == -1 ) { ++ dev->rom_size = 0x10000; ++ } else if ( fstat( fd, & st ) == -1 ) { ++ close( fd ); ++ dev->rom_size = 0x10000; ++ } else { ++ close( fd ); ++ dev->rom_size = st.st_size == 0 ? 0x10000 : st.st_size; ++ } ++ + return err; + } + +@@ -309,7 +327,6 @@ pci_device_linux_sysfs_read_rom( struct pci_device * dev, void * buffer ) + int fd; + struct stat st; + int err = 0; +- size_t rom_size; + size_t total_bytes; + + +@@ -334,10 +351,6 @@ pci_device_linux_sysfs_read_rom( struct pci_device * dev, void * buffer ) + return errno; + } + +- rom_size = st.st_size; +- if ( rom_size == 0 ) +- rom_size = 0x10000; +- + /* This is a quirky thing on Linux. Even though the ROM and the file + * for the ROM in sysfs are read-only, the string "1" must be written to + * the file to enable the ROM. After the data has been read, "0" must be +@@ -346,9 +359,9 @@ pci_device_linux_sysfs_read_rom( struct pci_device * dev, void * buffer ) + write( fd, "1", 1 ); + lseek( fd, 0, SEEK_SET ); + +- for ( total_bytes = 0 ; total_bytes < rom_size ; /* empty */ ) { ++ for ( total_bytes = 0 ; total_bytes < dev->rom_size ; /* empty */ ) { + const int bytes = read( fd, (char *) buffer + total_bytes, +- rom_size - total_bytes ); ++ dev->rom_size - total_bytes ); + if ( bytes == -1 ) { + err = errno; + break; diff --git a/libpciaccess.spec b/libpciaccess.spec new file mode 100644 index 0000000..b49b062 --- /dev/null +++ b/libpciaccess.spec @@ -0,0 +1,75 @@ +Name: libpciaccess +Version: 0.14 +Release: 3 +Summary: Generic PCI access library +License: MIT +URL: https://www.x.org/ + +Source0: https://www.x.org/archive/individual/lib/%{name}-%{version}.tar.bz2 +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot + + +Patch0: libpciaccess-rom-size.patch +Patch6000: 6000-linux-Set-number-of-devices-to-0-in-case-of-error.patch + +BuildRequires: autoconf automake libtool pkgconfig git xorg-x11-util-macros +Requires: hwdata + +%description +Provides functionality for X to access the PCI bus and devices in a +platform-independent way. + +%package devel +Summary: PCI access library development package +Requires: %{name} = %{version}-%{release} +Requires: pkgconfig + +%description devel +This package contains the development headers for the library. + +%prep +%autosetup -Sgit -n %{name}-%{version} + +%build +%configure --disable-static +make %{?_smp_mflags} + +%install +%make_install +rm -f $RPM_BUILD_ROOT/%{_libdir}/*.la + +%post -p /sbin/ldconfig +%postun -p /sbin/ldconfig + +%files +%defattr(-,root,root,-) +%license COPYING +%doc AUTHORS +%{_libdir}/libpciaccess.so.0* + +%files devel +%defattr(-,root,root,-) +%{_includedir}/* +%{_libdir}/libpciaccess.so +%{_libdir}/pkgconfig/pciaccess.pc + + +%changelog +* Tue Aug 27 2019 zoujing - 0.14-3 +- Type:enhancemnet +- ID:NA +- SUG:NA +- DESCi:openEuler Debranding + +* Wed Aug 21 2019 wubo - 0.14-2.2 +- change patch name + +* Thu Apr 18 2019 wangxiao - 0.14-2.1 +- Type:bugfix +- ID:NA +- SUG:restart +- DESC:Set number of devices to 0 in case of error + +* Wed Apr 17 2019 openEuler Buildteam - 0.14-2 +- Package Initialization +