From 468a3b9904402330ca6d65af08ef346f945360e3 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 13 Apr 2021 07:37:26 +0200 Subject: [PATCH 01/10] Use tiRPC --- config.mk | 2 +- library/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.mk b/config.mk index 8705dcd..75b2de1 100644 --- a/config.mk +++ b/config.mk @@ -1,4 +1,4 @@ -CFLAGS=-g +CFLAGS=$(OPTS) $(shell pkg-config --cflags libtirpc) LDFLAGS= INSTALL=install diff --git a/library/Makefile b/library/Makefile index 881b419..63e232b 100644 --- a/library/Makefile +++ b/library/Makefile @@ -11,7 +11,7 @@ endif all : libvxi11.so.${SOVERSION} libvxi11.so.${SOVERSION} : vxi11_user.o vxi11_clnt.o vxi11_xdr.o - $(CC) $(LDFLAGS) -shared -Wl,-soname,libvxi11.so.${SOVERSION} $^ -o $@ + $(CC) $(LDFLAGS) -shared -Wl,-soname,libvxi11.so.${SOVERSION} $^ -o $@ $(shell pkg-config --libs libtirpc) vxi11_user.o: vxi11_user.c vxi11.h $(CC) -fPIC $(CFLAGS) -c $< -o $@ From ace5068a0e408957886e59e342436b8954d909e1 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 13 Apr 2021 07:38:36 +0200 Subject: [PATCH 02/10] Fix install use --- library/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Makefile b/library/Makefile index 63e232b..e5c253f 100644 --- a/library/Makefile +++ b/library/Makefile @@ -36,5 +36,5 @@ install: all $(INSTALL) libvxi11.so.${SOVERSION} $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/ ln -sf libvxi11.so.${SOVERSION} $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/libvxi11.so $(INSTALL) -d $(DESTDIR)$(prefix)/include/ - $(INSTALL) vxi11_user.h $(DESTDIR)$(prefix)/include/ + $(INSTALL) -m644 vxi11_user.h $(DESTDIR)$(prefix)/include/ From ddb27d64acd42354857b262bd8cd81e522dee3be Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 13 Apr 2021 07:46:52 +0200 Subject: [PATCH 03/10] Fix potential read out of bounds The vxi11_open_device function keeps a list of known clients which includes the address. This is a string which can be an IP address (of fixed length) but could also be host names. Change the structure to use a zero-length array for the address and allocate memory according to the address string's length. --- CHANGELOG-UD.txt | 14 ++++++++++++++ library/vxi11_user.c | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 CHANGELOG-UD.txt diff --git a/CHANGELOG-UD.txt b/CHANGELOG-UD.txt new file mode 100644 index 0000000..6e15de9 --- /dev/null +++ b/CHANGELOG-UD.txt @@ -0,0 +1,14 @@ + +Post vxi11 2.0 - 2021-04-13 +--------------------------- +These are the changes made on a clone of the official repository. An +appropriate pull request will be made but for the time being the changes +are documented separately. + +* Use tiRPC and link with appropriate libraries. This is needed for + modern Linux systems because the old SunRPC code is only available + for compatibility +* Fix use of install which installs with execute permission by default + which is wrong for the header file +* Fix potentially non-terminated string in _vxi11_client_t list which + has a fixed-size buffer for a file name diff --git a/library/vxi11_user.c b/library/vxi11_user.c index de216ed..35ef044 100644 --- a/library/vxi11_user.c +++ b/library/vxi11_user.c @@ -65,11 +65,11 @@ struct _VXI11_CLINK { struct _vxi11_client_t { struct _vxi11_client_t *next; - char address[20]; #ifndef WIN32 CLIENT *client_address; #endif int link_count; + char address[0]; }; static struct _vxi11_client_t *VXI11_CLIENTS = NULL; @@ -156,7 +156,7 @@ int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device) * is, for this address. Because it's a new client, this * must be link number 1. Keep track of how many devices we've * opened so we don't run out of storage space. */ - client = (struct _vxi11_client_t *)calloc(1, sizeof(struct _vxi11_client_t)); + client = (struct _vxi11_client_t *)calloc(1, sizeof(struct _vxi11_client_t) + strlen(address) + 1); if (!client) { free(*clink); *clink = NULL; @@ -183,7 +183,7 @@ int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device) return 1; } - strncpy(client->address, address, 20); + strcpy(client->address, address); client->client_address = (*clink)->client; client->link_count = 1; client->next = VXI11_CLIENTS; From bdffb21a9ebad2a00a9a0dfff2846ad11f5fc484 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 13 Apr 2021 07:50:12 +0200 Subject: [PATCH 04/10] Fix vxi11_cmd input handling The code ignored fgets failures which might lead to undefined behavior and potentially out-of-bound reads. Actually return the error of the loop as the program's exit status --- CHANGELOG-UD.txt | 2 ++ utils/vxi11_cmd.c | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-UD.txt b/CHANGELOG-UD.txt index 6e15de9..ab69b3d 100644 --- a/CHANGELOG-UD.txt +++ b/CHANGELOG-UD.txt @@ -12,3 +12,5 @@ are documented separately. which is wrong for the header file * Fix potentially non-terminated string in _vxi11_client_t list which has a fixed-size buffer for a file name +* Handle fgets failure (e.g., on EOF) in vxi11_cmd. Actually return + the error diff --git a/utils/vxi11_cmd.c b/utils/vxi11_cmd.c index 74df81c..fa6cabd 100644 --- a/utils/vxi11_cmd.c +++ b/utils/vxi11_cmd.c @@ -63,7 +63,8 @@ int main(int argc, char *argv[]) memset(cmd, 0, 256); // initialize command string memset(buf, 0, BUF_LEN); // initialize buffer printf("Input command or query ('q' to exit): "); - fgets(cmd, 256, stdin); + if (fgets(cmd, 256, stdin) == NULL) + break; cmd[strlen(cmd) - 1] = 0; // just gets rid of the \n if (strncasecmp(cmd, "q", 1) == 0) { break; @@ -85,5 +86,5 @@ int main(int argc, char *argv[]) } ret = vxi11_close_device(clink, device_ip); - return 0; + return ret; } From 60c3af57fcb68f050618139c6dae2a4ebb8d24e0 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 13 Apr 2021 07:53:20 +0200 Subject: [PATCH 05/10] Fix argument handling in vxi11_send Simplify argument handling in vxi11_send and in the process fix unnecessary truncation of the command and potential out-of-bounds read --- CHANGELOG-UD.txt | 3 +++ utils/vxi11_send.c | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG-UD.txt b/CHANGELOG-UD.txt index ab69b3d..ef11336 100644 --- a/CHANGELOG-UD.txt +++ b/CHANGELOG-UD.txt @@ -14,3 +14,6 @@ are documented separately. has a fixed-size buffer for a file name * Handle fgets failure (e.g., on EOF) in vxi11_cmd. Actually return the error +* Simplify argument handling in vxi11_send and in the process fix + unnecessary truncation of the command and potential out-of-bounds + read diff --git a/utils/vxi11_send.c b/utils/vxi11_send.c index afeef87..52f941f 100644 --- a/utils/vxi11_send.c +++ b/utils/vxi11_send.c @@ -35,11 +35,11 @@ int main(int argc, char *argv[]) { - static char *device_ip; - char cmd[256]; + char *device_ip; + char *cmd; VXI11_CLINK *clink; - if (argc < 2) { + if (argc < 3) { printf("usage: %s your.inst.ip.addr command\n", argv[0]); exit(1); } @@ -51,8 +51,7 @@ int main(int argc, char *argv[]) exit(2); } - memset(cmd, 0, 256); // initialize command string - strncpy(cmd, argv[2], 256); + cmd = argv[2]; vxi11_send(clink, cmd, strlen(cmd)); vxi11_close_device(clink, device_ip); return 0; From 3f7cfe8663d2b104b00be4c8968d9b024aa33ac1 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 13 Apr 2021 07:58:51 +0200 Subject: [PATCH 06/10] Install python code This was missing from 'make install' --- CHANGELOG-UD.txt | 1 + Makefile | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG-UD.txt b/CHANGELOG-UD.txt index ef11336..0145e77 100644 --- a/CHANGELOG-UD.txt +++ b/CHANGELOG-UD.txt @@ -17,3 +17,4 @@ are documented separately. * Simplify argument handling in vxi11_send and in the process fix unnecessary truncation of the command and potential out-of-bounds read +* Install python code as well diff --git a/Makefile b/Makefile index 7761e9e..277e755 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,8 @@ install : all dist : distclean mkdir vxi11-$(VERSION) cp -pr library utils vxi11-$(VERSION)/ + mkdir vxi11-$(VERSION)/python + cp python/setup.py python/vxi11.py vxi11-$(VERSION)/python cp -p config.mk Makefile CMakeLists.txt CHANGELOG.txt README.md GNU_General_Public_License.txt vxi11-$(VERSION)/ tar -zcf vxi11-$(VERSION).tar.gz vxi11-$(VERSION) From 3e432afe225e85190e0f5b82a0ad3cc322cc428a Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 13 Apr 2021 08:08:48 +0200 Subject: [PATCH 07/10] Add Fedora .spec file With this .spec file the package is compiled and packaged in four different RPM files (plus the debug information). The library, header, utilities, and the Python code can be installed separately. The library is a dependency for the other packages, though. Because Fedora (and upstream) for some time has deprecated Python 2 the code is only packaged for Python 3. --- CHANGELOG-UD.txt | 1 + Makefile | 4 +- vxi11.spec | 108 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 vxi11.spec diff --git a/CHANGELOG-UD.txt b/CHANGELOG-UD.txt index 0145e77..060812f 100644 --- a/CHANGELOG-UD.txt +++ b/CHANGELOG-UD.txt @@ -18,3 +18,4 @@ are documented separately. unnecessary truncation of the command and potential out-of-bounds read * Install python code as well +* Add .spec file for Fedora diff --git a/Makefile b/Makefile index 277e755..889c97b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=2.0 +VERSION=2.0ud.1 include config.mk @@ -20,7 +20,7 @@ dist : distclean cp -pr library utils vxi11-$(VERSION)/ mkdir vxi11-$(VERSION)/python cp python/setup.py python/vxi11.py vxi11-$(VERSION)/python - cp -p config.mk Makefile CMakeLists.txt CHANGELOG.txt README.md GNU_General_Public_License.txt vxi11-$(VERSION)/ + cp -p config.mk Makefile CMakeLists.txt CHANGELOG.txt README.md GNU_General_Public_License.txt vxi11.spec vxi11-$(VERSION)/ tar -zcf vxi11-$(VERSION).tar.gz vxi11-$(VERSION) distclean : clean diff --git a/vxi11.spec b/vxi11.spec new file mode 100644 index 0000000..feafa3c --- /dev/null +++ b/vxi11.spec @@ -0,0 +1,108 @@ +Summary: VXI11 Device Communication +Name: vxi11 +Version: 2.0ud.1 +Release: 1 +URL: https://github.com/drepper/vxi11.git +Source: vxi11-2.0ud.1.tar.gz +License: GPLv2+ + +BuildRequires: gcc +BuildRequires: make +BuildRequires: libtirpc-devel +BuildRequires: rpcgen +BuildRequires: pkgconf-pkg-config +BuildRequires: sed + +%define abi 1 + +%description +This library allows communication using the VXI11 RPC protocol with +Ethernet-enabled devices such as oscilloscopes, logic analyzers, +function generators, power supplies, etc. The specific commands vary +by device. + +%package utils +Summary: Utilities to use VXI11 library to control devices +License: GPLv2+ +Requires: vxi11 = %{version}-%{release} + +%description utils +This package contains the utilities which use the VXI11 library to +control devices. The vxi11_cmd utility provides a simple interactive +shell to send commands and queries to one device at a time. The +vxi11_send utility allows to send a single command to a device. + +%package devel +Summary: Files needed for using the VXI11 library +License: GPLv2+ +Requires: vxi11 = %{version}-%{release} + +%description devel +The vxi11-devel package contains the files needed to write code that +uses the libvxi11 library. + +%package -n python3-vxi11 +Summary: Python interface to VXI11 library +License: GPLv2+ +Requires: vxi11 = %{version}-%{release} + +%description -n python3-vxi11 +This package contains a Python binding of the libvxi11 library to +control Ethernet-enabled devices. + +%prep +%setup -q + +%build +make OPTS="${RPM_OPT_FLAGS} -Wno-unused-variable" CC=gcc + +cd python +%py3_build +cd .. + +%install +rm -rf ${RPM_BUILD_ROOT} +mkdir -p ${RPM_BUILD_ROOT}%{_prefix} + +%make_install prefix=%{_prefix} LIB_SUFFIX=$(echo %{_lib}|sed 's/lib//') + +cd python +%py3_install +cd .. + +%clean +rm -fr ${RPM_BUILD_ROOT} + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%defattr(-,root,root) +%license GNU_General_Public_License.txt +%doc README.md CHANGELOG.txt +%{_libdir}/libvxi11.so.%{abi} + +%files utils +%defattr(-,root,root) +%{_bindir}/vxi11_cmd +%{_bindir}/vxi11_send + +%files devel +%defattr(-,root,root) +%{_libdir}/libvxi11.so +%{_includedir}/vxi11_user.h + +%files -n python3-vxi11 +%defattr(-,root,root) +%{python3_sitelib}/vxi11.py +%{python3_sitelib}/vxi11-*.egg-info +%{python3_sitelib}/__pycache__/* + +%changelog +* Tue Apr 13 2021 Ulrich Drepper 2.0ud.1-1 +- Build based on cloned git repository which contains the patches +* Mon Apr 12 2021 Ulrich Drepper 2.0-1 +- Create Fedora .spec file for the unchanged git repository +- fix a few bugs including potential buffer overruns +- add patch to distribute python code From 668979c8bb550260cddc64694949194f31e1372d Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 13 Apr 2021 08:12:21 +0200 Subject: [PATCH 08/10] Add tarballs to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4fcd01f..8e7bf70 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ vxi11_send *.o *.pyc .pc/ +vxi11-*.tar.gz From 5f96127e3f599b4f727b0fc87ba9e6c75fd76045 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 13 Apr 2021 08:28:07 +0200 Subject: [PATCH 09/10] Simplify lib directory name handling Instead of using LIB_SUFFIX simply get the entire directory name from a variable. This matches the variable _lib in RPM --- CHANGELOG-UD.txt | 1 + library/Makefile | 8 +++++--- vxi11.spec | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG-UD.txt b/CHANGELOG-UD.txt index 060812f..4cda3f9 100644 --- a/CHANGELOG-UD.txt +++ b/CHANGELOG-UD.txt @@ -19,3 +19,4 @@ are documented separately. read * Install python code as well * Add .spec file for Fedora +* Simplify library directory name handling diff --git a/library/Makefile b/library/Makefile index e5c253f..aec6711 100644 --- a/library/Makefile +++ b/library/Makefile @@ -8,6 +8,8 @@ ifneq ($(UNAME),SunOS) LDFLAGS:=$(LDFLAGS) -Wl,--version-script=linker.version endif +lib = lib + all : libvxi11.so.${SOVERSION} libvxi11.so.${SOVERSION} : vxi11_user.o vxi11_clnt.o vxi11_xdr.o @@ -32,9 +34,9 @@ clean: rm -f *.o libvxi11.so.${SOVERSION} vxi11.h vxi11_svc.c vxi11_xdr.c vxi11_clnt.c TAGS install: all - $(INSTALL) -d $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/ - $(INSTALL) libvxi11.so.${SOVERSION} $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/ - ln -sf libvxi11.so.${SOVERSION} $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/libvxi11.so + $(INSTALL) -d $(DESTDIR)$(prefix)/${lib}/ + $(INSTALL) libvxi11.so.${SOVERSION} $(DESTDIR)$(prefix)/${lib}/ + ln -sf libvxi11.so.${SOVERSION} $(DESTDIR)$(prefix)/${lib}/libvxi11.so $(INSTALL) -d $(DESTDIR)$(prefix)/include/ $(INSTALL) -m644 vxi11_user.h $(DESTDIR)$(prefix)/include/ diff --git a/vxi11.spec b/vxi11.spec index feafa3c..813dcb2 100644 --- a/vxi11.spec +++ b/vxi11.spec @@ -64,7 +64,7 @@ cd .. rm -rf ${RPM_BUILD_ROOT} mkdir -p ${RPM_BUILD_ROOT}%{_prefix} -%make_install prefix=%{_prefix} LIB_SUFFIX=$(echo %{_lib}|sed 's/lib//') +%make_install prefix=%{_prefix} lib=%{_lib} cd python %py3_install From 1ac0e17f7b669458cc7a4f0642b11beaeaf7be97 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 13 Apr 2021 12:18:52 +0200 Subject: [PATCH 10/10] Automatically determine name of lib directory --- CHANGELOG-UD.txt | 1 + library/Makefile | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-UD.txt b/CHANGELOG-UD.txt index 4cda3f9..435f11a 100644 --- a/CHANGELOG-UD.txt +++ b/CHANGELOG-UD.txt @@ -20,3 +20,4 @@ are documented separately. * Install python code as well * Add .spec file for Fedora * Simplify library directory name handling +* Automatically determine correct lib directory name diff --git a/library/Makefile b/library/Makefile index aec6711..e84b80a 100644 --- a/library/Makefile +++ b/library/Makefile @@ -8,7 +8,7 @@ ifneq ($(UNAME),SunOS) LDFLAGS:=$(LDFLAGS) -Wl,--version-script=linker.version endif -lib = lib +lib = $(shell $(CC) -print-search-dirs|grep '^libraries'|tr ':' '\n'|sed -n 's|.*/\([^/]\+\)/\?$$|\1|p'|grep -m1 'lib\(64\|32\|x32\)') all : libvxi11.so.${SOVERSION}