From 05c7637a53cff48b9f0959726bdc29105fa08391 Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Apr 10 2018 05:42:45 +0000 Subject: import libsmbios-2.3.3-6.el7 --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b1323ea --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +SOURCES/v2.3.3.tar.gz diff --git a/.libsmbios.metadata b/.libsmbios.metadata new file mode 100644 index 0000000..4518a3c --- /dev/null +++ b/.libsmbios.metadata @@ -0,0 +1 @@ +c0f9a8ddf5f13fd2ca9b3ab18bee07b54c74dd1a SOURCES/v2.3.3.tar.gz diff --git a/README.md b/README.md deleted file mode 100644 index 98f42b4..0000000 --- a/README.md +++ /dev/null @@ -1,4 +0,0 @@ -The master branch has no content - -Look at the c7 branch if you are working with CentOS-7, or the c4/c5/c6 branch for CentOS-4, 5 or 6 -If you find this file in a distro specific branch, it means that no content has been checked in yet diff --git a/SOURCES/0001-Don-t-build-the-yum-plugin.patch b/SOURCES/0001-Don-t-build-the-yum-plugin.patch new file mode 100644 index 0000000..f1b41a6 --- /dev/null +++ b/SOURCES/0001-Don-t-build-the-yum-plugin.patch @@ -0,0 +1,26 @@ +From 707a262b5038d48877e30e6e6b0ee08705766160 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 5 Oct 2017 14:29:17 -0400 +Subject: [PATCH 01/22] Don't build the yum plugin. + +Signed-off-by: Peter Jones +--- + Makefile.am | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/Makefile.am b/Makefile.am +index c0bafb802d1..7648132d968 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -41,7 +41,7 @@ endif + include src/libsmbios_c/Makefile.am + include src/python/Makefile.am + include src/py-cli/Makefile.am +-include src/yum-plugin/Makefile.am ++# include src/yum-plugin/Makefile.am + include src/bin/Makefile.am + include src/pyunit/Makefile.am + +-- +2.14.3 + diff --git a/SOURCES/0002-smbios-utils-bin-make-version-output-parsable-by-hel.patch b/SOURCES/0002-smbios-utils-bin-make-version-output-parsable-by-hel.patch new file mode 100644 index 0000000..75b2d85 --- /dev/null +++ b/SOURCES/0002-smbios-utils-bin-make-version-output-parsable-by-hel.patch @@ -0,0 +1,79 @@ +From 698c9ed5b86ce3a7400a08902464a6cade5b269b Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 5 Oct 2017 15:32:05 -0400 +Subject: [PATCH 02/22] smbios-utils-bin: make --version output parsable by + help2man. + +Signed-off-by: Peter Jones +--- + src/bin/smbios-get-ut-data.c | 2 +- + src/bin/smbios-state-byte-ctl.c | 5 +++++ + src/bin/smbios-sys-info-lite.c | 2 +- + src/bin/smbios-upflag-ctl.c | 2 +- + 4 files changed, 8 insertions(+), 3 deletions(-) + +diff --git a/src/bin/smbios-get-ut-data.c b/src/bin/smbios-get-ut-data.c +index 7b0b62c37ff..0387326181d 100644 +--- a/src/bin/smbios-get-ut-data.c ++++ b/src/bin/smbios-get-ut-data.c +@@ -81,7 +81,7 @@ main (int argc, char **argv) + memory_obj_factory(MEMORY_UNIT_TEST_MODE | MEMORY_GET_SINGLETON, args); + break; + case 255: +- printf(_("Libsmbios: %s\n"), smbios_get_library_version_string()); ++ printf("%s\n", smbios_get_library_version_string()); + exit(0); + break; + default: +diff --git a/src/bin/smbios-state-byte-ctl.c b/src/bin/smbios-state-byte-ctl.c +index b22e50efef2..559d2c3fa3d 100644 +--- a/src/bin/smbios-state-byte-ctl.c ++++ b/src/bin/smbios-state-byte-ctl.c +@@ -48,6 +48,7 @@ struct options opts[] = + { 2, "cmos_file", N_("Debug: CMOS dump file to use instead of physical cmos"), "c", 1 }, + { 3, "set", N_("Set CMOS state byte to new value"), "s", 1 }, + { 4, "owner", N_("Set state byte owner"), "o", 1 }, ++ { 255, "version", N_("Display libsmbios version information"), "v", 0 }, + { 0, NULL, NULL, NULL, 0 } + }; + +@@ -82,6 +83,10 @@ main (int argc, char **argv) + case 4: + owner = strtoul( args, 0, 0 ); + break; ++ case 255: ++ printf("%s\n", smbios_get_library_version_string()); ++ exit(0); ++ break; + default: + break; + } +diff --git a/src/bin/smbios-sys-info-lite.c b/src/bin/smbios-sys-info-lite.c +index 6fa9c7cb0b7..d594aefcfe3 100644 +--- a/src/bin/smbios-sys-info-lite.c ++++ b/src/bin/smbios-sys-info-lite.c +@@ -84,7 +84,7 @@ main (int argc, char **argv) + memory_obj_factory(MEMORY_UNIT_TEST_MODE | MEMORY_GET_SINGLETON, args); + break; + case 255: +- printf( _("Libsmbios version: %s\n"), smbios_get_library_version_string()); ++ printf("%s\n", smbios_get_library_version_string()); + exit(0); + break; + default: +diff --git a/src/bin/smbios-upflag-ctl.c b/src/bin/smbios-upflag-ctl.c +index 28f628bee2f..f1725f4a85d 100644 +--- a/src/bin/smbios-upflag-ctl.c ++++ b/src/bin/smbios-upflag-ctl.c +@@ -84,7 +84,7 @@ main (int argc, char **argv) + sysinfo_set_up_boot_flag( flag ); + break; + case 255: +- printf( _("Libsmbios version: %s\n"), smbios_get_library_version_string()); ++ printf("%s\n", smbios_get_library_version_string()); + exit(0); + break; + default: +-- +2.14.3 + diff --git a/SOURCES/0003-smbios-utils-python-make-version-output-parsable-by-.patch b/SOURCES/0003-smbios-utils-python-make-version-output-parsable-by-.patch new file mode 100644 index 0000000..4c909af --- /dev/null +++ b/SOURCES/0003-smbios-utils-python-make-version-output-parsable-by-.patch @@ -0,0 +1,254 @@ +From 743df4855c2395cd8797c6e6406c8091d90a9b8b Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 5 Oct 2017 15:35:45 -0400 +Subject: [PATCH 03/22] smbios-utils-python: make --version output parsable by + help2man. + +Signed-off-by: Peter Jones +--- + src/bin/smbios-battery-ctl | 3 ++- + src/bin/smbios-keyboard-ctl | 3 ++- + src/bin/smbios-lcd-brightness | 5 +++-- + src/bin/smbios-passwd | 5 +++-- + src/bin/smbios-sys-info | 3 ++- + src/bin/smbios-thermal-ctl | 3 ++- + src/bin/smbios-token-ctl | 5 +++-- + src/bin/smbios-wakeup-ctl | 5 +++-- + src/bin/smbios-wireless-ctl | 3 ++- + 9 files changed, 22 insertions(+), 13 deletions(-) + mode change 100644 => 100755 src/bin/smbios-battery-ctl + mode change 100644 => 100755 src/bin/smbios-keyboard-ctl + mode change 100644 => 100755 src/bin/smbios-lcd-brightness + mode change 100644 => 100755 src/bin/smbios-passwd + mode change 100644 => 100755 src/bin/smbios-sys-info + mode change 100644 => 100755 src/bin/smbios-thermal-ctl + mode change 100644 => 100755 src/bin/smbios-token-ctl + mode change 100644 => 100755 src/bin/smbios-wakeup-ctl + mode change 100644 => 100755 src/bin/smbios-wireless-ctl + +diff --git a/src/bin/smbios-battery-ctl b/src/bin/smbios-battery-ctl +old mode 100644 +new mode 100755 +index bf24f086d1c..7b4f93e57f6 +--- a/src/bin/smbios-battery-ctl ++++ b/src/bin/smbios-battery-ctl +@@ -20,7 +20,6 @@ import sys + + # the following vars are all substituted on install + # this bin isnt byte-compiled, so this is ok +-__VERSION__="uninstalled-version" + pythondir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "python") + clidir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "py-cli") + # end vars +@@ -33,6 +32,8 @@ import cli + from libsmbios_c import token, smbios, smi, system_info as sysinfo, localedir, GETTEXT_PACKAGE + from libsmbios_c.trace_decorator import decorate, traceLog, getLog + ++__VERSION__=sysinfo.get_library_version_string() ++ + locale.setlocale(locale.LC_ALL, '') + gettext.install(GETTEXT_PACKAGE, localedir, unicode=1) + +diff --git a/src/bin/smbios-keyboard-ctl b/src/bin/smbios-keyboard-ctl +old mode 100644 +new mode 100755 +index 6e12639406e..115535b0f14 +--- a/src/bin/smbios-keyboard-ctl ++++ b/src/bin/smbios-keyboard-ctl +@@ -22,7 +22,6 @@ import re + + # the following vars are all substituted on install + # this bin isnt byte-compiled, so this is ok +-__VERSION__="uninstalled-version" + pythondir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "python") + clidir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "py-cli") + # end vars +@@ -35,6 +34,8 @@ import cli + from libsmbios_c import token, smbios, smi, system_info as sysinfo, localedir, GETTEXT_PACKAGE + from libsmbios_c.trace_decorator import decorate, traceLog, getLog + ++__VERSION__=sysinfo.get_library_version_string() ++ + locale.setlocale(locale.LC_ALL, '') + gettext.install(GETTEXT_PACKAGE, localedir, unicode=1) + +diff --git a/src/bin/smbios-lcd-brightness b/src/bin/smbios-lcd-brightness +old mode 100644 +new mode 100755 +index 324191945ab..48992177fe2 +--- a/src/bin/smbios-lcd-brightness ++++ b/src/bin/smbios-lcd-brightness +@@ -21,7 +21,6 @@ import traceback + + # the following vars are all substituted on install + # this bin isnt byte-compiled, so this is ok +-__VERSION__="uninstalled-version" + pythondir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "python") + clidir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "py-cli") + # end vars +@@ -31,9 +30,11 @@ sys.path.insert(0,pythondir) + sys.path.insert(0,clidir) + + import cli +-from libsmbios_c import smi, token, localedir, GETTEXT_PACKAGE ++from libsmbios_c import smi, token, localedir, GETTEXT_PACKAGE, system_info as sysinfo + from libsmbios_c.trace_decorator import decorate, traceLog, getLog + ++__VERSION__=sysinfo.get_library_version_string() ++ + locale.setlocale(locale.LC_ALL, '') + gettext.install(GETTEXT_PACKAGE, localedir, unicode=1) + +diff --git a/src/bin/smbios-passwd b/src/bin/smbios-passwd +old mode 100644 +new mode 100755 +index bdfaae8e15c..db7e2860199 +--- a/src/bin/smbios-passwd ++++ b/src/bin/smbios-passwd +@@ -20,7 +20,6 @@ import traceback + + # the following vars are all substituted on install + # this bin isnt byte-compiled, so this is ok +-__VERSION__="uninstalled-version" + pythondir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "python") + clidir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "py-cli") + # end vars +@@ -30,9 +29,11 @@ sys.path.insert(0,pythondir) + sys.path.insert(0,clidir) + + import cli +-from libsmbios_c import smi, localedir, GETTEXT_PACKAGE ++from libsmbios_c import smi, localedir, GETTEXT_PACKAGE, system_info as sysinfo + from libsmbios_c.trace_decorator import decorate, traceLog, getLog + ++__VERSION__=sysinfo.get_library_version_string() ++ + locale.setlocale(locale.LC_ALL, '') + gettext.install(GETTEXT_PACKAGE, localedir, unicode=1) + +diff --git a/src/bin/smbios-sys-info b/src/bin/smbios-sys-info +old mode 100644 +new mode 100755 +index cba8e3b7599..d9c0732f2fa +--- a/src/bin/smbios-sys-info ++++ b/src/bin/smbios-sys-info +@@ -20,7 +20,6 @@ import exceptions + + # the following vars are all substituted on install + # this bin isnt byte-compiled, so this is ok +-__VERSION__="uninstalled-version" + pythondir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "python") + clidir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "py-cli") + # end vars +@@ -33,6 +32,8 @@ import cli + from libsmbios_c import system_info as sysinfo, smbios, localedir, GETTEXT_PACKAGE + from libsmbios_c.trace_decorator import decorate, traceLog, getLog + ++__VERSION__=sysinfo.get_library_version_string() ++ + locale.setlocale(locale.LC_ALL, '') + gettext.install(GETTEXT_PACKAGE, localedir, unicode=1) + +diff --git a/src/bin/smbios-thermal-ctl b/src/bin/smbios-thermal-ctl +old mode 100644 +new mode 100755 +index aebd4d1223e..18bba2a784a +--- a/src/bin/smbios-thermal-ctl ++++ b/src/bin/smbios-thermal-ctl +@@ -20,7 +20,6 @@ import sys + + # the following vars are all substituted on install + # this bin isnt byte-compiled, so this is ok +-__VERSION__="uninstalled-version" + pythondir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "python") + clidir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "py-cli") + # end vars +@@ -33,6 +32,8 @@ import cli + from libsmbios_c import token, smbios, smi, system_info as sysinfo, localedir, GETTEXT_PACKAGE + from libsmbios_c.trace_decorator import decorate, traceLog, getLog + ++__VERSION__=sysinfo.get_library_version_string() ++ + locale.setlocale(locale.LC_ALL, '') + gettext.install(GETTEXT_PACKAGE, localedir, unicode=1) + +diff --git a/src/bin/smbios-token-ctl b/src/bin/smbios-token-ctl +old mode 100644 +new mode 100755 +index d64a3d914d2..6d9a27b0214 +--- a/src/bin/smbios-token-ctl ++++ b/src/bin/smbios-token-ctl +@@ -25,7 +25,6 @@ import traceback + + # the following vars are all substituted on install + # this bin isnt byte-compiled, so this is ok +-__VERSION__="uninstalled-version" + pythondir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "python") + clidir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "py-cli") + # end vars +@@ -35,9 +34,11 @@ sys.path.insert(0,pythondir) + sys.path.insert(0,clidir) + + import cli +-from libsmbios_c import token, localedir, GETTEXT_PACKAGE, pkgdatadir ++from libsmbios_c import token, localedir, GETTEXT_PACKAGE, pkgdatadir, system_info as sysinfo + from libsmbios_c.trace_decorator import decorate, traceLog, getLog + ++__VERSION__=sysinfo.get_library_version_string() ++ + locale.setlocale(locale.LC_ALL, '') + gettext.install(GETTEXT_PACKAGE, localedir, unicode=1) + +diff --git a/src/bin/smbios-wakeup-ctl b/src/bin/smbios-wakeup-ctl +old mode 100644 +new mode 100755 +index da38f9ea1ad..c4c19ff499e +--- a/src/bin/smbios-wakeup-ctl ++++ b/src/bin/smbios-wakeup-ctl +@@ -22,7 +22,6 @@ import traceback + + # the following vars are all substituted on install + # this bin isnt byte-compiled, so this is ok +-__VERSION__="uninstalled-version" + pythondir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "python") + clidir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "py-cli") + # end vars +@@ -32,9 +31,11 @@ sys.path.insert(0,pythondir) + sys.path.insert(0,clidir) + + import cli +-from libsmbios_c import token, localedir, GETTEXT_PACKAGE ++from libsmbios_c import token, localedir, GETTEXT_PACKAGE, system_info as sysinfo + from libsmbios_c.trace_decorator import decorate, traceLog, getLog + ++__VERSION__=sysinfo.get_library_version_string() ++ + locale.setlocale(locale.LC_ALL, '') + gettext.install(GETTEXT_PACKAGE, localedir, unicode=1) + +diff --git a/src/bin/smbios-wireless-ctl b/src/bin/smbios-wireless-ctl +old mode 100644 +new mode 100755 +index 66650a12512..ca277bcca5b +--- a/src/bin/smbios-wireless-ctl ++++ b/src/bin/smbios-wireless-ctl +@@ -20,7 +20,6 @@ import traceback + + # the following vars are all substituted on install + # this bin isnt byte-compiled, so this is ok +-__VERSION__="uninstalled-version" + pythondir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "python") + clidir=os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), "..", "py-cli") + # end vars +@@ -33,6 +32,8 @@ import cli + from libsmbios_c import token, smbios, smi, system_info as sysinfo, localedir, GETTEXT_PACKAGE + from libsmbios_c.trace_decorator import decorate, traceLog, getLog + ++__VERSION__=sysinfo.get_library_version_string() ++ + locale.setlocale(locale.LC_ALL, '') + gettext.install(GETTEXT_PACKAGE, localedir, unicode=1) + +-- +2.14.3 + diff --git a/SOURCES/0004-Force-python-to-install-to-site-arch-not-site-packag.patch b/SOURCES/0004-Force-python-to-install-to-site-arch-not-site-packag.patch new file mode 100644 index 0000000..410f95b --- /dev/null +++ b/SOURCES/0004-Force-python-to-install-to-site-arch-not-site-packag.patch @@ -0,0 +1,25 @@ +From 734913528ec1c05b6b0b28b13f876155a7d8f52d Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Tue, 13 Feb 2018 16:35:12 -0500 +Subject: [PATCH 04/22] Force python to install to site-arch not site-packages + +Signed-off-by: Peter Jones +--- + src/python/Makefile.am | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/python/Makefile.am b/src/python/Makefile.am +index 608b48e934e..c14aa8f8e6b 100644 +--- a/src/python/Makefile.am ++++ b/src/python/Makefile.am +@@ -1,6 +1,6 @@ + # vim:noexpandtab:autoindent:tabstop=8:shiftwidth=8:filetype=make:nocindent:tw=0: + +-pkgpythondir=$(pythondir)/libsmbios_c ++pkgpythondir=$(pyexecdir)/libsmbios_c + + if HAVE_PYTHON + pkgpython_PYTHON = \ +-- +2.14.3 + diff --git a/SOURCES/0005-Add-stuff-generated-during-the-build-to-.gitignore.patch b/SOURCES/0005-Add-stuff-generated-during-the-build-to-.gitignore.patch new file mode 100644 index 0000000..2574aac --- /dev/null +++ b/SOURCES/0005-Add-stuff-generated-during-the-build-to-.gitignore.patch @@ -0,0 +1,40 @@ +From eeac9f5d7b51f1ce593d7456a598d154bfeca035 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 14:48:22 -0400 +Subject: [PATCH 05/22] Add stuff generated during the build to .gitignore + +Signed-off-by: Peter Jones +--- + .gitignore | 19 +++++++++++++++++++ + 1 file changed, 19 insertions(+) + +diff --git a/.gitignore b/.gitignore +index 09ca33f4fdc..eda4ea6e975 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -46,3 +46,22 @@ po/remove-potcdate.sin + # docker build process + /Dockerfile + /*-entrypoint.sh ++ ++AUTHORS ++ChangeLog ++Makefile ++config.log ++config.status ++libsmbios-*.tar.* ++*.spec ++*.pc ++libtool ++out/ ++pkg/pkginfo ++pkg/test-driver ++po/POTFILES ++po/en@boldquot.insert-header ++po/en@quot.insert-header ++po/remove-potcdate.sed ++po/stamp-po ++src/python/_vars.py +-- +2.14.3 + diff --git a/SOURCES/0006-Enable-Wextra-with-some-minor-caveats.patch b/SOURCES/0006-Enable-Wextra-with-some-minor-caveats.patch new file mode 100644 index 0000000..b13bf58 --- /dev/null +++ b/SOURCES/0006-Enable-Wextra-with-some-minor-caveats.patch @@ -0,0 +1,49 @@ +From 5363df45176e6052ab828432dc47258d149489ff Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 12:48:41 -0400 +Subject: [PATCH 06/22] Enable -Wextra, with some minor caveats. + +In recent gcc, -Wextra gives you a lot of pretty good info, so it's +worth using. It also has some not very useful things. + +This patch enables -Wextra and then turns off some of the more annoying, +less concretely a problem cases. + +Signed-off-by: Peter Jones +--- + src/bin/smbios-get-ut-data.c | 2 ++ + Makefile.am | 4 ++-- + 2 files changed, 4 insertions(+), 2 deletions(-) + +diff --git a/src/bin/smbios-get-ut-data.c b/src/bin/smbios-get-ut-data.c +index 0387326181d..11875941594 100644 +--- a/src/bin/smbios-get-ut-data.c ++++ b/src/bin/smbios-get-ut-data.c +@@ -177,7 +177,9 @@ void dumpMem( const char *fn, size_t offset, size_t len) + memory_read(buf, offset, len); + int recs = fwrite(buf, len, 1, fd); + if (recs != 1) ++ { + ; // nada ++ } + free(buf); + fclose(fd); + } +diff --git a/Makefile.am b/Makefile.am +index 7648132d968..8b9f4185bc1 100644 +--- a/Makefile.am ++++ b/Makefile.am +@@ -18,8 +18,8 @@ lib_LTLIBRARIES= + TESTS= + + AM_CPPFLAGS = -I$(top_builddir)/out/include -I$(top_srcdir)/src/include -DLIBSMBIOS_LOCALEDIR=\"$(localedir)\" +-AM_CFLAGS = -Wall -fPIC +-AM_CXXFLAGS = -Wall -fPIC ++AM_CFLAGS = -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -fPIC ++AM_CXXFLAGS = -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -fPIC + AM_LDADD = $(LIBINTL) + + AM_LDFLAGS = -L$(top_builddir)/out/ +-- +2.14.3 + diff --git a/SOURCES/0007-Don-t-compare-signed-and-unsigned-values-in-loop-ite.patch b/SOURCES/0007-Don-t-compare-signed-and-unsigned-values-in-loop-ite.patch new file mode 100644 index 0000000..7ccf683 --- /dev/null +++ b/SOURCES/0007-Don-t-compare-signed-and-unsigned-values-in-loop-ite.patch @@ -0,0 +1,115 @@ +From 05125ce636ff0f93ae6a3d6f44032b4053324ff7 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 13:04:26 -0400 +Subject: [PATCH 07/22] Don't compare signed and unsigned values in loop + iterators. +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +-Wextra finds: + +src/libsmbios_c/token/token_d4.c: In function ‘_d4_get_string’: +src/libsmbios_c/token/token_d4.c:168:20: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] + for (int i=0; i +--- + src/libsmbios_c/smi/smi_obj.c | 2 +- + src/libsmbios_c/smi/smi_password.c | 6 +++--- + src/libsmbios_c/token/checksum.c | 4 ++-- + src/libsmbios_c/token/token_d4.c | 4 ++-- + 4 files changed, 8 insertions(+), 8 deletions(-) + +diff --git a/src/libsmbios_c/smi/smi_obj.c b/src/libsmbios_c/smi/smi_obj.c +index 71cb83b0d67..2149020ac86 100644 +--- a/src/libsmbios_c/smi/smi_obj.c ++++ b/src/libsmbios_c/smi/smi_obj.c +@@ -201,7 +201,7 @@ u8 * dell_smi_obj_make_buffer_frombios_withheader(struct dell_smi_obj *this, u8 + if(buf) + { + // write buffer pattern +- for (int i=0; icsumlen; ++i ) ++ for( unsigned int i=0; icsumlen; ++i ) + { + u8 byte; + int ret = cmos_obj_read_byte(c, &byte, data->indexPort, data->dataPort, data->csumloc+i); +@@ -70,7 +70,7 @@ __hidden int update_checksum(const struct cmos_access_obj *c, bool do_update, vo + { + // write new checksum + fnprintf("REWRITE CSUM\n"); +- for( int i=0; icsumlen; ++i ) ++ for( unsigned int i=0; icsumlen; ++i ) + { + int ret = cmos_obj_write_byte(c, data->indexPort, data->dataPort, data->csumloc+i, csum[data->csumlen -i -1]); + if (ret) +diff --git a/src/libsmbios_c/token/token_d4.c b/src/libsmbios_c/token/token_d4.c +index bc46e1a71af..6447114ee0a 100644 +--- a/src/libsmbios_c/token/token_d4.c ++++ b/src/libsmbios_c/token/token_d4.c +@@ -165,7 +165,7 @@ static char * _d4_get_string(const struct token_obj *t, size_t *len) + if (!retval) + goto out_err; + +- for (int i=0; iindexPort, +@@ -206,7 +206,7 @@ static int _d4_set_string(const struct token_obj *t, const char *str, size_t siz + + memcpy( targetBuffer, str, size < strSize ? size : strSize ); + +- for (int i=0; iindexPort, + cast_struct(t)->dataPort, +-- +2.14.3 + diff --git a/SOURCES/0008-Fix-some-missing-error-checks-that-covscan-found.patch b/SOURCES/0008-Fix-some-missing-error-checks-that-covscan-found.patch new file mode 100644 index 0000000..50c4da2 --- /dev/null +++ b/SOURCES/0008-Fix-some-missing-error-checks-that-covscan-found.patch @@ -0,0 +1,90 @@ +From f0898fec9f637bd6fe05cf9445c7bc92ef8ce221 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 12:27:52 -0400 +Subject: [PATCH 08/22] Fix some missing error checks that covscan found. + +Signed-off-by: Peter Jones +--- + src/bin/smbios-get-ut-data.c | 38 ++++++++++++++++++++++++++++------- + src/libsmbios_c/system_info/up_flag.c | 7 ++++++- + 2 files changed, 37 insertions(+), 8 deletions(-) + +diff --git a/src/bin/smbios-get-ut-data.c b/src/bin/smbios-get-ut-data.c +index 11875941594..4bdf102a7dc 100644 +--- a/src/bin/smbios-get-ut-data.c ++++ b/src/bin/smbios-get-ut-data.c +@@ -114,6 +114,11 @@ void dumpCmosIndexPort(const char *fn, u32 indexPort, u32 dataPort) + + // ensure file exists + FILE *fd = fopen(cmosDumpFile, "a+"); ++ if (!fd) ++ { ++ printf( _("error opening dump file \"%s\": %m\n"), cmosDumpFile); ++ return; ++ } + fclose(fd); + + cmos = cmos_obj_factory(CMOS_GET_SINGLETON); +@@ -172,15 +177,34 @@ out: + + void dumpMem( const char *fn, size_t offset, size_t len) + { +- FILE *fd = fopen( fn, "w+" ); +- u8 *buf = calloc(1, len); +- memory_read(buf, offset, len); ++ FILE *fd = NULL; ++ u8 *buf = NULL; ++ int ret; ++ ++ fd = fopen( fn, "w+" ); ++ if (!fd) ++ { ++ printf( _("error opening dump file \"%s\": %m\n"), fn); ++ return; ++ } ++ buf = calloc(1, len); ++ if (!buf) ++ { ++ printf( _("could not allocate memory: %m\n")); ++ goto err; ++ } ++ ret = memory_read(buf, offset, len); ++ if (ret < 0) ++ { ++ printf( _("could not read from memory: %m\n")); ++ goto err; ++ } + int recs = fwrite(buf, len, 1, fd); + if (recs != 1) +- { +- ; // nada +- } +- free(buf); ++ printf( _("could not write to \"%s\": %m\n"), fn); ++err: ++ if (buf) ++ free(buf); + fclose(fd); + } + +diff --git a/src/libsmbios_c/system_info/up_flag.c b/src/libsmbios_c/system_info/up_flag.c +index 77298410386..e52462d896e 100644 +--- a/src/libsmbios_c/system_info/up_flag.c ++++ b/src/libsmbios_c/system_info/up_flag.c +@@ -57,7 +57,12 @@ __hidden bool get_up_offset_and_flag(struct up_info *up) + offset = memory_search( UP_ANCHOR, UP_ANCHOR_LEN, 0xF0000UL, 0xFFFFFUL, 1); + + if (offset!=0 && offset!=-1) +- memory_read(up, (u64)offset, sizeof(*up)); ++ { ++ int ret; ++ ret = memory_read(up, (u64)offset, sizeof(*up)); ++ if (ret < 0) ++ return false; ++ } + + fnprintf("offset 0x%llx", offset); + return (offset!=0 && offset!=-1); +-- +2.14.3 + diff --git a/SOURCES/0009-Check-for-fseek-errors-everywhere.patch b/SOURCES/0009-Check-for-fseek-errors-everywhere.patch new file mode 100644 index 0000000..2471c83 --- /dev/null +++ b/SOURCES/0009-Check-for-fseek-errors-everywhere.patch @@ -0,0 +1,263 @@ +From 6bc66384084a018724b0c94ed30088dff5130e16 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 12:32:49 -0400 +Subject: [PATCH 09/22] Check for fseek errors everywhere. + +covscan noticed these aren't checked. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/smi/smi_linux.c | 5 ++++- + src/libsmbios_c/smi/smi_solaris.c | 6 +++++- + src/libsmbios_c++/smi/SmiImpl.h | 4 +++- + src/libsmbios_c++/cmos/CmosRW.cpp | 16 ++++++++++++++-- + src/libsmbios_c++/smi/Smi_Linux.cpp | 22 ++++++++++++++++++---- + src/libsmbios_c++/smi/Smi_Solaris.cpp | 23 ++++++++++++++++++----- + 6 files changed, 62 insertions(+), 14 deletions(-) + +diff --git a/src/libsmbios_c/smi/smi_linux.c b/src/libsmbios_c/smi/smi_linux.c +index c97489fed42..f810b43e699 100644 +--- a/src/libsmbios_c/smi/smi_linux.c ++++ b/src/libsmbios_c/smi/smi_linux.c +@@ -59,6 +59,7 @@ u32 __hidden get_phys_buf_addr() + FILE *fd = 0; + u32 physaddr = 0; + char linebuf[bufsize] = {0,}; ++ int ret; + + fnprintf("\n"); + +@@ -68,7 +69,9 @@ u32 __hidden get_phys_buf_addr() + if (!fd) + goto out; + +- fseek(fd, 0L, 0); ++ ret = fseek(fd, 0L, 0); ++ if (ret < 0) ++ goto out_close; + size_t numBytes = fread(linebuf, 1, bufsize, fd); + if (!numBytes) + goto out_close; +diff --git a/src/libsmbios_c/smi/smi_solaris.c b/src/libsmbios_c/smi/smi_solaris.c +index bb407750ba1..d190305c8f8 100644 +--- a/src/libsmbios_c/smi/smi_solaris.c ++++ b/src/libsmbios_c/smi/smi_solaris.c +@@ -59,6 +59,7 @@ u32 __internal get_phys_buf_addr() + FILE *fd = 0; + u32 physaddr = 0; + char linebuf[bufsize] = {0,}; ++ int ret; + + fnprintf("\n"); + +@@ -68,7 +69,10 @@ u32 __internal get_phys_buf_addr() + if (!fd) + goto out; + +- fseek(fd, 0L, 0); ++ ret = fseek(fd, 0L, 0); ++ if (ret < 0) ++ goto out_close; ++ + size_t numBytes = fread(linebuf, 1, bufsize, fd); + if (!numBytes) + goto out_close; +diff --git a/src/libsmbios_c++/smi/SmiImpl.h b/src/libsmbios_c++/smi/SmiImpl.h +index 6373d79d0ca..b448e5d8087 100644 +--- a/src/libsmbios_c++/smi/SmiImpl.h ++++ b/src/libsmbios_c++/smi/SmiImpl.h +@@ -84,7 +84,9 @@ namespace smi + }; + virtual void execute() + { +- fseek(fh,0,0); ++ int ret = fseek(fh,0,0); ++ if (ret < 0) ++ throw std::exception(); + }; + virtual void getResultBuffer(u8 *buffer, size_t size) + { +diff --git a/src/libsmbios_c++/cmos/CmosRW.cpp b/src/libsmbios_c++/cmos/CmosRW.cpp +index 32642228176..c4274d4b2f7 100644 +--- a/src/libsmbios_c++/cmos/CmosRW.cpp ++++ b/src/libsmbios_c++/cmos/CmosRW.cpp +@@ -118,6 +118,7 @@ namespace cmos + // + u8 CmosRWFile::readByte (u32 indexPort, u32 dataPort, u32 offset) const + { ++ int ret; + u8 retval = 0xFF; + u32 realOffset = indexPort * 256 + offset; + (void) dataPort; // unused +@@ -127,7 +128,12 @@ namespace cmos + if( !fh ) + throw smbios::InternalErrorImpl(errMessage + strerror(errno)); + +- fseek (fh, static_cast(realOffset), SEEK_SET); ++ ret = fseek (fh, static_cast(realOffset), SEEK_SET); ++ if (ret < 0) ++ { ++ fclose (fh); ++ throw std::exception(); ++ } + size_t numRecs = fread (&retval, sizeof (retval), 1, fh); // only used in unit tests, so isnt critical + fclose (fh); + if (numRecs != 1) +@@ -141,6 +147,7 @@ namespace cmos + void CmosRWFile::writeByte (u32 indexPort, u32 dataPort, u32 offset, u8 byte) const + { + //cout << "w(" << offset << ")"; ++ int ret; + u32 realOffset = indexPort * 256 + offset; + (void) dataPort; // unused + string errMessage("Could not open CMOS file(" + fileName + ") for writing: "); +@@ -149,7 +156,12 @@ namespace cmos + if( !fh ) + throw smbios::InternalErrorImpl(errMessage + strerror(errno)); + +- fseek (fh, static_cast(realOffset), SEEK_SET); ++ ret = fseek (fh, static_cast(realOffset), SEEK_SET); ++ if (ret < 0) ++ { ++ fclose (fh); ++ throw std::exception(); ++ } + size_t recs = fwrite (&byte, sizeof (byte), 1, fh); + fclose (fh); + fflush(NULL); +diff --git a/src/libsmbios_c++/smi/Smi_Linux.cpp b/src/libsmbios_c++/smi/Smi_Linux.cpp +index 3107d892296..5f3ecc31017 100644 +--- a/src/libsmbios_c++/smi/Smi_Linux.cpp ++++ b/src/libsmbios_c++/smi/Smi_Linux.cpp +@@ -76,6 +76,7 @@ namespace smi + + void SmiArchStrategy::lock() + { ++ int ret; + smiLinuxPrivateData *tmpPrivPtr = reinterpret_cast(privateData); + + +@@ -89,9 +90,13 @@ namespace smi + + flock( fileno(tmpPrivPtr->fh_data), LOCK_EX ); + +- fseek(tmpPrivPtr->fh_doReq, 0L, 0); ++ ret = fseek(tmpPrivPtr->fh_doReq, 0L, 0); ++ if (ret < 0) ++ throw std::exception(); + FWRITE("0", 1, 1, tmpPrivPtr->fh_doReq); +- fseek(tmpPrivPtr->fh_doReq, 0L, 0); ++ ret = fseek(tmpPrivPtr->fh_doReq, 0L, 0); ++ if (ret < 0) ++ throw std::exception(); + } + + size_t SmiArchStrategy::getPhysicalBufferBaseAddress() +@@ -99,6 +104,7 @@ namespace smi + const int bufSize=63; + char tmpBuf[bufSize+1] = {0,}; + size_t retval = 0; ++ int ret; + + fflush(NULL); + +@@ -106,7 +112,12 @@ namespace smi + if( ! fh ) + throw smbios::InternalErrorImpl("Could not open file " SMI_PHYS_ADDR_FILE ". Check that dcdbas driver is properly loaded."); + +- fseek(fh, 0L, 0); ++ ret = fseek(fh, 0L, 0); ++ if (ret < 0) ++ { ++ fclose(fh); ++ throw std::exception(); ++ } + size_t numBytes = fread(tmpBuf, 1, bufSize, fh); + fclose(fh); + fh=0; +@@ -155,11 +166,14 @@ namespace smi + + void SmiArchStrategy::execute() + { ++ int ret; + smiLinuxPrivateData *tmpPrivPtr = reinterpret_cast(privateData); + fflush(NULL); + FWRITE("1", 1, 1, tmpPrivPtr->fh_doReq); + fflush(NULL); +- fseek(tmpPrivPtr->fh_data, 0L, 0); ++ ret = fseek(tmpPrivPtr->fh_data, 0L, 0); ++ if (ret < 0) ++ throw std::exception(); + } + + void SmiArchStrategy::finish() +diff --git a/src/libsmbios_c++/smi/Smi_Solaris.cpp b/src/libsmbios_c++/smi/Smi_Solaris.cpp +index d2190eea479..7ffce233e34 100644 +--- a/src/libsmbios_c++/smi/Smi_Solaris.cpp ++++ b/src/libsmbios_c++/smi/Smi_Solaris.cpp +@@ -79,7 +79,7 @@ namespace smi + void SmiArchStrategy::lock() + { + smiSolarisPrivateData *tmpPrivPtr = reinterpret_cast(privateData); +- ++ int ret; + + tmpPrivPtr->fh_data = fopen(SMI_DATA_FILE, "r+b"); + if( ! tmpPrivPtr->fh_data ) +@@ -89,9 +89,13 @@ namespace smi + if( ! tmpPrivPtr->fh_doReq) + throw smbios::InternalErrorImpl("Could not open file " SMI_DO_REQUEST_FILE ". Check that dcdbas driver is properly loaded."); + +- fseek(tmpPrivPtr->fh_doReq, 0L, 0); ++ ret = fseek(tmpPrivPtr->fh_doReq, 0L, 0); ++ if (ret < 0) ++ throw std::exception(); + FWRITE("0", 1, 1, tmpPrivPtr->fh_doReq); +- fseek(tmpPrivPtr->fh_doReq, 0L, 0); ++ ret = fseek(tmpPrivPtr->fh_doReq, 0L, 0); ++ if (ret < 0) ++ throw std::exception(); + } + + size_t SmiArchStrategy::getPhysicalBufferBaseAddress() +@@ -99,6 +103,7 @@ namespace smi + const int bufSize=63; + char tmpBuf[bufSize+1] = {0,}; + size_t retval = 0; ++ int ret; + + fflush(NULL); + +@@ -106,7 +111,12 @@ namespace smi + if( ! fh ) + throw smbios::InternalErrorImpl("Could not open file " SMI_PHYS_ADDR_FILE ". Check that dcdbas driver is properly loaded."); + +- fseek(fh, 0L, 0); ++ ret = fseek(fh, 0L, 0); ++ if (ret < 0) ++ { ++ fclose(fh); ++ throw std::exception(); ++ } + size_t numBytes = fread(tmpBuf, 1, bufSize, fh); + fclose(fh); + fh=0; +@@ -155,11 +165,14 @@ namespace smi + + void SmiArchStrategy::execute() + { ++ int ret; + smiSolarisPrivateData *tmpPrivPtr = reinterpret_cast(privateData); + fflush(NULL); + FWRITE("1", 1, 1, tmpPrivPtr->fh_doReq); + fflush(NULL); +- fseek(tmpPrivPtr->fh_data, 0L, 0); ++ ret = fseek(tmpPrivPtr->fh_data, 0L, 0); ++ if (ret < 0) ++ throw std::exception(); + } + + void SmiArchStrategy::finish() +-- +2.14.3 + diff --git a/SOURCES/0010-Fix-a-data-leak-on-the-failure-path.patch b/SOURCES/0010-Fix-a-data-leak-on-the-failure-path.patch new file mode 100644 index 0000000..4f45588 --- /dev/null +++ b/SOURCES/0010-Fix-a-data-leak-on-the-failure-path.patch @@ -0,0 +1,43 @@ +From 0abcf3d717acc336a29d30120f164a7f2e9d60e4 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 14:57:29 -0400 +Subject: [PATCH 10/22] Fix a data leak on the failure path. + +Covscan says: + +Error: RESOURCE_LEAK (CWE-772): [#def17] +libsmbios-2.3.3/src/libsmbios_c/cmos/cmos_obj.c:76: alloc_fn: Storage is returned from allocation function "calloc". +libsmbios-2.3.3/src/libsmbios_c/cmos/cmos_obj.c:76: var_assign: Assigning: "toReturn" = storage returned from "calloc(1UL, 72UL)". +libsmbios-2.3.3/src/libsmbios_c/cmos/cmos_obj.c:88: noescape: Resource "toReturn" is not freed or pointed-to in "init_cmos_struct". +libsmbios-2.3.3/src/libsmbios_c/cmos/cmos_linux.c:54:55: noescape: "init_cmos_struct(struct cmos_access_obj *)" does not free or save its parameter "m". +libsmbios-2.3.3/src/libsmbios_c/cmos/cmos_obj.c:97: overwrite_var: Overwriting "toReturn" in "toReturn = NULL" leaks the storage that "toReturn" points to. + +And it's right; none of the failure paths actually free toReturn, only +things it points to. + +This patch removes a bogus comment and frees the memory correctly. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/cmos/cmos_obj.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/libsmbios_c/cmos/cmos_obj.c b/src/libsmbios_c/cmos/cmos_obj.c +index 04b81866a71..0b6c62544b2 100644 +--- a/src/libsmbios_c/cmos/cmos_obj.c ++++ b/src/libsmbios_c/cmos/cmos_obj.c +@@ -91,9 +91,9 @@ LIBSMBIOS_C_DLL_SPEC struct cmos_access_obj *cmos_obj_factory(int flags, ...) + if (ret==0) + goto out; + +- // fail. init_cmos_* functions are responsible for free-ing memory if they +- // return failure. + toReturn->initialized = 0; ++ if (toReturn != &singleton) ++ free(toReturn); + toReturn = 0; + + out: +-- +2.14.3 + diff --git a/SOURCES/0011-Fix-an-incorrect-error-check.patch b/SOURCES/0011-Fix-an-incorrect-error-check.patch new file mode 100644 index 0000000..2c99111 --- /dev/null +++ b/SOURCES/0011-Fix-an-incorrect-error-check.patch @@ -0,0 +1,105 @@ +From 9fa6f3c3ad54d00550f67c8fba0459c22778b0f3 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 15:08:19 -0400 +Subject: [PATCH 11/22] Fix an incorrect error check. + +covscan says: +Error: REVERSE_INULL (CWE-476): [#def18] +libsmbios-2.3.3/src/libsmbios_c/memory/memory_linux.c:260: deref_ptr: Directly dereferencing pointer "private_data". +libsmbios-2.3.3/src/libsmbios_c/memory/memory_linux.c:262: check_after_deref: Null-checking "private_data" suggests that it may be null, but it has already been dereferenced on all paths leading to the check. + +And it's right; private_data->filename has been assigned to between +allocating private_data and checking for success. Also the free() path +on the error pathway has some invalid reference possibilities in it. + +It also says: + +Error: FORWARD_NULL (CWE-476): [#def19] +libsmbios-2.3.3/src/libsmbios_c/memory/memory_linux.c:262: var_compare_op: Comparing "private_data->filename" to null implies that "private_data->filename" might be null. +libsmbios-2.3.3/src/libsmbios_c/memory/memory_linux.c:291: var_deref_model: Passing null pointer "private_data->filename" to "strlcat", which dereferences it. +libsmbios-2.3.3/src/libsmbios_c/common/strlcat.c:34:19: var_assign_parm: Assigning: "s" = "src". +libsmbios-2.3.3/src/libsmbios_c/common/strlcat.c:45:9: deref_var_in_call: Function "strlen" dereferences "s" (which is a copy of "src"). + +And we can just use fn here instead. + +So this patch fixes all that up. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/memory/memory_linux.c | 31 ++++++++++++++++++++----------- + 1 file changed, 20 insertions(+), 11 deletions(-) + +diff --git a/src/libsmbios_c/memory/memory_linux.c b/src/libsmbios_c/memory/memory_linux.c +index 61532af3dbd..85994e334fe 100644 +--- a/src/libsmbios_c/memory/memory_linux.c ++++ b/src/libsmbios_c/memory/memory_linux.c +@@ -234,14 +234,19 @@ static void linux_free(struct memory_access_obj *this) + struct linux_data *private_data = (struct linux_data *)this->private_data; + fnprintf("\n"); + +- free(this->errstring); +- this->errstring = 0; ++ if (this->errstring) ++ free(this->errstring); ++ this->errstring = NULL; + +- free(private_data->filename); +- private_data->filename = 0; ++ if (private_data) ++ { ++ if (private_data->filename) ++ free(private_data->filename); ++ private_data->filename = NULL; + +- free(private_data); +- this->private_data = 0; ++ free(private_data); ++ this->private_data = NULL; ++ } + + this->initialized=0; + } +@@ -251,22 +256,27 @@ __hidden int init_mem_struct_filename(struct memory_access_obj *m, const char *f + char *errbuf=0; + int retval = 0; + const char *error; ++ struct linux_data *private_data; + + fnprintf("\n"); + + // do allocations + error = _("There was an allocation failure while trying to construct the memory object. Filename: "); +- struct linux_data *private_data = calloc(1, sizeof(struct linux_data)); ++ ++ m->private_data = NULL; ++ m->private_data = private_data = calloc(1, sizeof(struct linux_data)); ++ if (!private_data) ++ goto out_fail; ++ + private_data->filename = calloc(1, strlen(fn) + 1); + m->errstring = calloc(1, ERROR_BUFSIZE); +- if (!private_data || !private_data->filename || !m->errstring) ++ if (!private_data->filename || !m->errstring) + goto out_fail; + + strcat(private_data->filename, fn); + private_data->lastMappedOffset = -1; + private_data->rw = 0; + private_data->mappingSize = getpagesize(); // must be power of 2, >= getpagesize() +- m->private_data = private_data; + + m->free = linux_free; + m->read_fn = linux_read_fn; +@@ -287,8 +297,7 @@ out_fail: + errbuf = memory_get_module_error_buf(); + if (errbuf){ + strlcpy(errbuf, error, ERROR_BUFSIZE); +- +- strlcat(errbuf, private_data->filename, ERROR_BUFSIZE); ++ strlcat(errbuf, fn, ERROR_BUFSIZE); + strlcat(errbuf, _("\nThe OS Error string was: "), ERROR_BUFSIZE); + fixed_strerror(errno, errbuf, ERROR_BUFSIZE); + } +-- +2.14.3 + diff --git a/SOURCES/0012-Simplify-smbios_table_free-token_table_free-and-cmos.patch b/SOURCES/0012-Simplify-smbios_table_free-token_table_free-and-cmos.patch new file mode 100644 index 0000000..5b3a81b --- /dev/null +++ b/SOURCES/0012-Simplify-smbios_table_free-token_table_free-and-cmos.patch @@ -0,0 +1,198 @@ +From bb3d555d99f4015be2a517e3267c0cf6dc0021f9 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 15:20:58 -0400 +Subject: [PATCH 12/22] Simplify smbios_table_free(), token_table_free(), and + cmos_obj_free() + +Covscan noticed: +Error: BAD_FREE (CWE-763): [#def46] +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios_obj.c:80: address_assign: Assigning: "toReturn" = "&singleton". +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios_obj.c:87: incorrect_free: "init_smbios_struct" frees incorrect pointer "toReturn". +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios_obj.c:370:5: freed_arg: "smbios_table_free" frees parameter "m". +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios_obj.c:111:9: freed_arg: "_smbios_table_free" frees parameter "m". +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios_obj.c:330:5: freed_arg: "free" frees parameter "this". + +Covscan noticed: +Error: BAD_FREE (CWE-763): [#def46] +libsmbios-2.3.3/src/libsmbios_c/token/token_obj.c:82: address_assign: Assigning: "toReturn" = "&singleton". +libsmbios-2.3.3/src/libsmbios_c/token/token_obj.c:95: incorrect_free: "token_table_free" frees incorrect pointer "toReturn". +libsmbios-2.3.3/src/libsmbios_c/token/token_obj.c:109:9: freed_arg: "_token_table_free" frees parameter "m". +libsmbios-2.3.3/src/libsmbios_c/token/token_obj.c:249:5: freed_arg: "free" frees parameter "this". + +Error: BAD_FREE (CWE-763): [#def1] +libsmbios-2.3.3/src/libsmbios_c/cmos/cmos_obj.c:74: address_assign: Assigning: "toReturn" = "&singleton". +libsmbios-2.3.3/src/libsmbios_c/cmos/cmos_obj.c:95: incorrect_free: "free" frees incorrect pointer "toReturn". + +I don't think there's any way to actually hit that path, but there's +also no reason the code needs to have the extra level of indirection for +_smbios_table_free(), _token_table_free(), or _cmos_obj_free(), so just +simplify those out of existence. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/cmos/cmos_obj.c | 25 +++++++++---------------- + src/libsmbios_c/smbios/smbios_obj.c | 37 +++++++++++++++---------------------- + src/libsmbios_c/token/token_obj.c | 24 ++++++++++-------------- + 3 files changed, 34 insertions(+), 52 deletions(-) + +diff --git a/src/libsmbios_c/cmos/cmos_obj.c b/src/libsmbios_c/cmos/cmos_obj.c +index 0b6c62544b2..ef145f60d2f 100644 +--- a/src/libsmbios_c/cmos/cmos_obj.c ++++ b/src/libsmbios_c/cmos/cmos_obj.c +@@ -155,16 +155,19 @@ out: + return retval; + } + +-void __hidden _cmos_obj_cleanup(struct cmos_access_obj *m) ++void cmos_obj_free(struct cmos_access_obj *m) + { ++ struct callback *ptr = 0; ++ struct callback *next = 0; ++ ++ if (!m) ++ return; ++ + if(m->cleanup) + m->cleanup(m); +-} + +-void __hidden _cmos_obj_free(struct cmos_access_obj *m) +-{ +- struct callback *ptr = 0; +- struct callback *next = 0; ++ if (m == &singleton) ++ return; + + ptr = m->cb_list_head; + // free callback list +@@ -193,16 +196,6 @@ void __hidden _cmos_obj_free(struct cmos_access_obj *m) + free(m); + } + +-void cmos_obj_free(struct cmos_access_obj *m) +-{ +- if (!m) goto out; +- _cmos_obj_cleanup(m); +- if (m != &singleton) +- _cmos_obj_free(m); +-out: +- return; +-} +- + void cmos_obj_register_write_callback(struct cmos_access_obj *m, cmos_write_callback cb_fn, void *userdata, void (*destructor)(void *)) + { + clear_err(m); +diff --git a/src/libsmbios_c/smbios/smbios_obj.c b/src/libsmbios_c/smbios/smbios_obj.c +index 2382d9fcd16..0a029a2734e 100644 +--- a/src/libsmbios_c/smbios/smbios_obj.c ++++ b/src/libsmbios_c/smbios/smbios_obj.c +@@ -104,14 +104,23 @@ out: + return toReturn; + } + +-void smbios_table_free(struct smbios_table *m) ++void smbios_table_free(struct smbios_table *this) + { +- if (!m) goto out; +- if (m != &singleton) +- _smbios_table_free(m); ++ if (!this || this == &singleton) ++ return; + +-out: +- return; ++ memset(&this->tep, 0, sizeof(this->tep)); ++ ++ free(this->errstring); ++ this->errstring = 0; ++ ++ free(this->table); ++ this->table = 0; ++ ++ this->initialized=0; ++ ++ memset(this, 0, sizeof(*this)); // big hammer ++ free(this); + } + + const char *smbios_table_strerror(const struct smbios_table *m) +@@ -314,22 +323,6 @@ void smbios_table_walk(struct smbios_table *table, void (*fn)(const struct smbio + * + **************************************************/ + +-void __hidden _smbios_table_free(struct smbios_table *this) +-{ +- memset(&this->tep, 0, sizeof(this->tep)); +- +- free(this->errstring); +- this->errstring = 0; +- +- free(this->table); +- this->table = 0; +- +- this->initialized=0; +- +- memset(this, 0, sizeof(*this)); // big hammer +- free(this); +-} +- + int __hidden init_smbios_struct(struct smbios_table *m) + { + char *errbuf; +diff --git a/src/libsmbios_c/token/token_obj.c b/src/libsmbios_c/token/token_obj.c +index 8f6aaac05cd..b5948ae5a86 100644 +--- a/src/libsmbios_c/token/token_obj.c ++++ b/src/libsmbios_c/token/token_obj.c +@@ -38,7 +38,7 @@ + + // forward declarations + static int init_token_table(struct token_table *); +-static void _token_table_free(struct token_table *); ++static void _token_table_free_tokens(struct token_table *this); + + // static vars + static struct token_table singleton; // auto-init to 0 +@@ -101,14 +101,20 @@ out: + return toReturn; + } + +- + void token_table_free(struct token_table *m) + { + fnprintf("\n"); +- if (m && m != &singleton) +- _token_table_free(m); + + // can do special cleanup for singleton, but none necessary atm ++ if (!m || m == &singleton) ++ return; ++ ++ _token_table_free_tokens(m); ++ ++ free(m->errstring); ++ m->errstring = 0; ++ ++ free(m); + } + + const char * token_table_strerror(const struct token_table *table) +@@ -239,16 +245,6 @@ static void _token_table_free_tokens(struct token_table *this) + this->list_head = 0; + } + +-static void _token_table_free(struct token_table *this) +-{ +- _token_table_free_tokens(this); +- +- free(this->errstring); +- this->errstring = 0; +- +- free(this); +-} +- + void __hidden add_token(struct token_table *t, struct token_obj *o) + { + struct token_obj *ptr = t->list_head; +-- +2.14.3 + diff --git a/SOURCES/0013-Fix-a-wrong-conditional.patch b/SOURCES/0013-Fix-a-wrong-conditional.patch new file mode 100644 index 0000000..eab3f81 --- /dev/null +++ b/SOURCES/0013-Fix-a-wrong-conditional.patch @@ -0,0 +1,35 @@ +From 3806e407b20e8d1de61d52559ad035492273b962 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 15:23:46 -0400 +Subject: [PATCH 13/22] Fix a wrong conditional. + +Covscan noticed: +Error: CONSTANT_EXPRESSION_RESULT (CWE-398): [#def22] +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios_obj.c:442: always_true_or: The "or" condition "tempTEP->major_ver != 2 || tempTEP->major_ver != 3" will always be true because "tempTEP->major_ver" cannot be equal to two different values at the same time, so it must be not equal to at least one of them. + +This code cannot possibly be right, so I'm assuming the idea is to fail +if it's not either 2 or 3. + +This patch changes it to check that. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/smbios/smbios_obj.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/libsmbios_c/smbios/smbios_obj.c b/src/libsmbios_c/smbios/smbios_obj.c +index 0a029a2734e..3cb4bd0526f 100644 +--- a/src/libsmbios_c/smbios/smbios_obj.c ++++ b/src/libsmbios_c/smbios/smbios_obj.c +@@ -432,7 +432,7 @@ bool __hidden validate_smbios_tep( const struct smbios_table_entry_point *tempTE + fnprintf("SMBIOS TEP csum %d.\n", (int)checksum); + if(checksum) // Checking entry point structure checksum + retval = false; // validation failed +- if(! (tempTEP->major_ver!=0x02 || tempTEP->major_ver!=0x03) ) // Checking smbios major version ++ if(tempTEP->major_ver != 0x02 && tempTEP->major_ver != 0x03) // Checking smbios major version + retval = false; // validation failed + + // Entry Point Length field is at least 0x1f. +-- +2.14.3 + diff --git a/SOURCES/0014-Fix-a-leaked-file-handle.patch b/SOURCES/0014-Fix-a-leaked-file-handle.patch new file mode 100644 index 0000000..3a478d8 --- /dev/null +++ b/SOURCES/0014-Fix-a-leaked-file-handle.patch @@ -0,0 +1,52 @@ +From b734de6ee0e39176d3f3f63ff20ba70c87d536af Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 15:26:50 -0400 +Subject: [PATCH 14/22] Fix a leaked file handle. + +Covscan noticed: + +Error: RESOURCE_LEAK (CWE-772): [#def34] +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:260: alloc_fn: Storage is returned from allocation function "open_request_file". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:191:5: alloc_fn: Storage is returned from allocation function "fopen". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:191:5: var_assign: Assigning: "fd" = "fopen(fn, "wb")". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:193:9: noescape: Resource "fd" is not freed or pointed-to in function "fileno". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:195:9: noescape: Resource "fd" is not freed or pointed-to in function "fwrite". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:199:5: return_alloc: Returning allocated memory "fd". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:260: var_assign: Assigning: "fd" = storage returned from "open_request_file()". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:287: noescape: Resource "fd" is not freed or pointed-to in "trigger_smi". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:148:33: noescape: "trigger_smi(FILE *)" does not free or save its parameter "fd". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:294: noescape: Resource "fd" is not freed or pointed-to in "fileno". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:316: leaked_storage: Variable "fd" going out of scope leaks the storage it points to. + +And right it is, so this patch closes that file at the appropriate time. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/smi/smi_linux.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/src/libsmbios_c/smi/smi_linux.c b/src/libsmbios_c/smi/smi_linux.c +index f810b43e699..46ad888282d 100644 +--- a/src/libsmbios_c/smi/smi_linux.c ++++ b/src/libsmbios_c/smi/smi_linux.c +@@ -90,7 +90,7 @@ out: + u32 __hidden set_phys_buf_size(u32 newsize) + { + char fn[bufsize] = {0,}; +- FILE *fd = 0; ++ FILE *fd = NULL; + char linebuf[bufsize] = {0,}; + u32 phys_buf_addr=0; + +@@ -299,6 +299,8 @@ int __hidden LINUX_dell_smi_obj_execute(struct dell_smi_obj *this) + // update smi buffer + copy_phys_bufs(this, kernel_buf, physaddr, FROM_KERNEL_BUF); + ++ fclose(fd); ++ + retval = 0; + goto out; + +-- +2.14.3 + diff --git a/SOURCES/0015-Fix-some-plausible-buffer-overruns.patch b/SOURCES/0015-Fix-some-plausible-buffer-overruns.patch new file mode 100644 index 0000000..672efde --- /dev/null +++ b/SOURCES/0015-Fix-some-plausible-buffer-overruns.patch @@ -0,0 +1,205 @@ +From 028c1900ad0994de033237eeb7afc93fa0a1a75c Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 15:40:00 -0400 +Subject: [PATCH 15/22] Fix some plausible buffer overruns. + +Covscan noticed these: + +Error: STRING_OVERFLOW (CWE-120): [#def28] +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:128: fixed_size_dest: You might overrun the 256-character fixed-size string "fn" by copying "sysfs_basedir" without checking the length. + +Error: STRING_OVERFLOW (CWE-120): [#def29] +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:129: fixed_size_dest: You might overrun the 256-character fixed-size string "fn" by copying "smi_data_fn" without checking the length. + +Error: STRING_OVERFLOW (CWE-120): [#def30] +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:170: fixed_size_dest: You might overrun the 256-character fixed-size string "fn" by copying "sysfs_basedir" without checking the length. + +Error: STRING_OVERFLOW (CWE-120): [#def31] +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:171: fixed_size_dest: You might overrun the 256-character fixed-size string "fn" by copying "smi_data_fn" without checking the length. + +Error: STRING_OVERFLOW (CWE-120): [#def32] +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:188: fixed_size_dest: You might overrun the 256-character fixed-size string "fn" by copying "sysfs_basedir" without checking the length. + +Error: STRING_OVERFLOW (CWE-120): [#def33] +libsmbios-2.3.3/src/libsmbios_c/smi/smi_linux.c:189: fixed_size_dest: You might overrun the 256-character fixed-size string "fn" by copying "smi_request_fn" without checking the length. + +I don't know how big they can actually be - it depends on what +sysfs_basedir winds up being, which I imagine is smallish so long as +sysfs is on /sys, but it doesn't need to be - but I think covscan is +right, if impractical. + +This patch replaces all of these with an allocate_path(a, b) call that +allocates the correct amount of space on the stack and copies the data +in. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/smi/smi_linux.c | 75 +++++++++++++++++++++++++++-------------- + 1 file changed, 50 insertions(+), 25 deletions(-) + +diff --git a/src/libsmbios_c/smi/smi_linux.c b/src/libsmbios_c/smi/smi_linux.c +index 46ad888282d..f7628a1800c 100644 +--- a/src/libsmbios_c/smi/smi_linux.c ++++ b/src/libsmbios_c/smi/smi_linux.c +@@ -22,6 +22,7 @@ + #include "smbios_c/compat.h" + + // system ++#include + #include + #include + #include +@@ -53,9 +54,22 @@ void set_basedir(const char *newdir) + sysfs_basedir = newdir; + } + ++#define allocate_path(a, b) ( \ ++ { \ ++ char *fn_; \ ++ size_t sz_ = strlen(a) + strlen(b) + 1; \ ++ fn_ = alloca(sz_); \ ++ if (fn_) \ ++ { \ ++ strcpy(fn_, (a)); \ ++ strcat(fn_, (b)); \ ++ } \ ++ fn_; \ ++ }) ++ + u32 __hidden get_phys_buf_addr() + { +- char fn[bufsize] = {0,}; ++ char *fn = NULL; + FILE *fd = 0; + u32 physaddr = 0; + char linebuf[bufsize] = {0,}; +@@ -63,8 +77,10 @@ u32 __hidden get_phys_buf_addr() + + fnprintf("\n"); + +- strcat(fn, sysfs_basedir); +- strcat(fn, smi_data_buf_phys_addr_fn); ++ fn = allocate_path(sysfs_basedir, smi_data_buf_phys_addr_fn); ++ if (!fn) ++ goto out; ++ + fd = fopen(fn, "rb"); + if (!fd) + goto out; +@@ -79,7 +95,8 @@ u32 __hidden get_phys_buf_addr() + physaddr = strtoll(linebuf, NULL, 16); + + out_close: +- fclose(fd); ++ if (fd) ++ fclose(fd); + fflush(NULL); + + out: +@@ -89,15 +106,17 @@ out: + // returns physaddr + u32 __hidden set_phys_buf_size(u32 newsize) + { +- char fn[bufsize] = {0,}; ++ char *fn; + FILE *fd = NULL; + char linebuf[bufsize] = {0,}; + u32 phys_buf_addr=0; + + fnprintf("\n"); + +- strcat(fn, sysfs_basedir); +- strcat(fn, smi_data_buf_size_fn); ++ fn = allocate_path(sysfs_basedir, smi_data_buf_size_fn); ++ if (!fn) ++ goto out; ++ + fd = fopen(fn, "w+b"); + if (!fd) + goto out; +@@ -107,26 +126,26 @@ u32 __hidden set_phys_buf_size(u32 newsize) + if (recs != 1) + goto out; + +- fclose(fd); +- +- fflush(NULL); +- + phys_buf_addr = get_phys_buf_addr(); +- goto out; + + out: ++ if (fd) ++ fclose(fd); ++ fflush(NULL); ++ + return phys_buf_addr; + } + + void __hidden write_smi_data(u8 *buffer, size_t size) + { +- char fn[bufsize] = {0,}; ++ char *fn; + FILE *fd = 0; + + fnprintf("\n"); + +- strcat(fn, sysfs_basedir); +- strcat(fn, smi_data_fn); ++ fn = allocate_path(sysfs_basedir, smi_data_fn); ++ if (!fn) ++ goto out; + + fnprintf("open data file: '%s'\n", fn); + +@@ -162,13 +181,15 @@ out: + + void __hidden get_smi_results(u8 *buffer, size_t size) + { +- char fn[bufsize] = {0,}; ++ char *fn; + FILE *fd = 0; + + fnprintf("\n"); + +- strcat(fn, sysfs_basedir); +- strcat(fn, smi_data_fn); ++ fn = allocate_path(sysfs_basedir, smi_data_fn); ++ if (!fn) ++ goto out; ++ + fd = fopen(fn, "rb"); + if (!fd) + goto out; +@@ -182,17 +203,21 @@ out: + + FILE *open_request_file() + { +- char fn[bufsize] = {0,}; ++ char *fn; + FILE *fd = 0; + int ret; +- strcat(fn, sysfs_basedir); +- strcat(fn, smi_request_fn); ++ ++ fn = allocate_path(sysfs_basedir, smi_request_fn); ++ if (!fn) ++ return NULL; ++ + fnprintf("open request file: '%s'\n", fn); + fd = fopen(fn, "wb"); +- if(fd) +- flock( fileno(fd), LOCK_EX ); +- if(fd) +- ret = fwrite("0", 1, 1, fd); ++ if (!fd) ++ return NULL; ++ ++ flock( fileno(fd), LOCK_EX ); ++ ret = fwrite("0", 1, 1, fd); + + fnprintf("got fd for request file: %p\n", fd); + UNREFERENCED_PARAMETER(ret); +-- +2.14.3 + diff --git a/SOURCES/0016-Don-t-leak-smbios_strerror-memory.patch b/SOURCES/0016-Don-t-leak-smbios_strerror-memory.patch new file mode 100644 index 0000000..182ca31 --- /dev/null +++ b/SOURCES/0016-Don-t-leak-smbios_strerror-memory.patch @@ -0,0 +1,86 @@ +From e1d8c422590daf34b364cb1df060b8e7257bd490 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 15:55:46 -0400 +Subject: [PATCH 16/22] Don't leak smbios_strerror() memory. + +Covscan noticed: + +Error: RESOURCE_LEAK (CWE-772): [#def35] +libsmbios-2.3.3/src/libsmbios_c/smi/smi_obj.c:310: alloc_fn: Storage is returned from allocation function "smbios_strerror". +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios.c:78:9: alloc_fn: Storage is returned from allocation function "strdup". +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios.c:78:9: var_assign: Assigning: "ret" = "strdup(smbios_table_strerror(table))". +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios.c:83:5: return_alloc: Returning allocated memory "ret". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_obj.c:310: noescape: Resource "smbios_strerror()" is not freed or pointed-to in "fprintf". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_obj.c:310: leaked_storage: Failing to save or free storage allocated by "smbios_strerror()" leaks it. + +Error: RESOURCE_LEAK (CWE-772): [#def36] +libsmbios-2.3.3/src/libsmbios_c/smi/smi_obj.c:311: alloc_fn: Storage is returned from allocation function "smbios_strerror". +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios.c:78:9: alloc_fn: Storage is returned from allocation function "strdup". +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios.c:78:9: var_assign: Assigning: "ret" = "strdup(smbios_table_strerror(table))". +libsmbios-2.3.3/src/libsmbios_c/smbios/smbios.c:83:5: return_alloc: Returning allocated memory "ret". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_obj.c:311: noescape: Resource "smbios_strerror()" is not freed or pointed-to in "strlcat". +libsmbios-2.3.3/src/libsmbios_c/common/strlcat.c:31:32: noescape: "strlcat(char *, char const *, size_t)" does not free or save its parameter "src". +libsmbios-2.3.3/src/libsmbios_c/smi/smi_obj.c:311: leaked_storage: Failing to save or free storage allocated by "smbios_strerror()" leaks it. + +This patch checks that returned allocation and frees it when we're done. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/smbios/smbios.c | 2 +- + src/libsmbios_c/smi/smi_obj.c | 11 ++++++++--- + src/include/smbios_c/smbios.h | 2 +- + 3 files changed, 10 insertions(+), 5 deletions(-) + +diff --git a/src/libsmbios_c/smbios/smbios.c b/src/libsmbios_c/smbios/smbios.c +index ff09cb1a614..f7b90109136 100644 +--- a/src/libsmbios_c/smbios/smbios.c ++++ b/src/libsmbios_c/smbios/smbios.c +@@ -69,7 +69,7 @@ struct smbios_struct *smbios_get_next_struct_by_handle(const struct smbios_struc + return ret; + } + +-const char *smbios_strerror(const struct smbios_struct *cur) ++char *smbios_strerror(const struct smbios_struct *cur) + { + char *ret; + struct smbios_table *table = smbios_table_factory(SMBIOS_DEFAULTS | SMBIOS_NO_ERR_CLEAR); +diff --git a/src/libsmbios_c/smi/smi_obj.c b/src/libsmbios_c/smi/smi_obj.c +index 2149020ac86..3c9a56b170a 100644 +--- a/src/libsmbios_c/smi/smi_obj.c ++++ b/src/libsmbios_c/smi/smi_obj.c +@@ -304,11 +304,16 @@ out_fail: + fnprintf(" out_fail \n"); + retval = -1; + errbuf = smi_get_module_error_buf(); +- if (errbuf){ ++ if (errbuf) { ++ char *smberr = smbios_strerror(); + fnprintf("error: %s\n", error); + strlcpy(errbuf, error, ERROR_BUFSIZE); +- fnprintf("smbios_strerror: %s\n", smbios_strerror()); +- strlcat(errbuf, smbios_strerror(), ERROR_BUFSIZE); ++ if (smberr) ++ { ++ fnprintf("smbios_strerror: %s\n", smberr); ++ strlcat(errbuf, smberr, ERROR_BUFSIZE); ++ free(smberr); ++ } + } + + out: +diff --git a/src/include/smbios_c/smbios.h b/src/include/smbios_c/smbios.h +index 4e1d631ca81..eb3b503204a 100644 +--- a/src/include/smbios_c/smbios.h ++++ b/src/include/smbios_c/smbios.h +@@ -127,7 +127,7 @@ LIBSMBIOS_C_DLL_SPEC const char * smbios_struct_get_string_number(const struct s + * Can return 0. The buffer used is guaranteed to be valid until the next call + * to any smbios_* function. Copy the contents if you need it longer. + */ +-LIBSMBIOS_C_DLL_SPEC const char * smbios_strerror(); ++LIBSMBIOS_C_DLL_SPEC char * smbios_strerror(); + + EXTERN_C_END; + +-- +2.14.3 + diff --git a/SOURCES/0017-Fix-some-impossible-logic.patch b/SOURCES/0017-Fix-some-impossible-logic.patch new file mode 100644 index 0000000..6fcd2d8 --- /dev/null +++ b/SOURCES/0017-Fix-some-impossible-logic.patch @@ -0,0 +1,91 @@ +From 248d2252c234434d443e07f339eecad74aa77bdc Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 16:25:12 -0400 +Subject: [PATCH 17/22] Fix some impossible logic. + +Covscan says: +Error: CONSTANT_EXPRESSION_RESULT (CWE-398): [#def37] +libsmbios-2.3.3/src/libsmbios_c/smi/smi_password.c:201: impossible_and: The "and" condition "tmpret == 0 && tmpret == 2" can never be true because "tmpret" cannot be equal to two different values at the same time. + +And it's right, that can't be correct. + +I've re-written most of the function here - I think it's "correct", but +the behavior doesn't appear to be well defined, so it's hard to be sure. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/smi/smi_password.c | 46 +++++++++++++++++--------------------- + 1 file changed, 21 insertions(+), 25 deletions(-) + +diff --git a/src/libsmbios_c/smi/smi_password.c b/src/libsmbios_c/smi/smi_password.c +index c24906aa2e2..b946b8d10af 100644 +--- a/src/libsmbios_c/smi/smi_password.c ++++ b/src/libsmbios_c/smi/smi_password.c +@@ -177,43 +177,39 @@ out: + + int dell_smi_password_verify(int which, const char *password) + { +- int retval = 2; + struct smi_password_properties p = {0,}; + int tmpret = get_password_properties_2(which, &p); +- if (tmpret == 0 && p.installed != 0) +- // if function succeeded and password *not* installed, skip +- goto out; +- else if (tmpret == 0) ++ ++ // if function succeeded and password *not* installed, skip ++ if (tmpret == 0 && p.installed != SMI_PASSWORD_INSTALLED) ++ return 2; ++ ++ if (tmpret == 0) + { +- // else _2 function is valid, so use it. + tmpret = verify_password_2(which, password, p.maxlen, 0); +- retval = 1; +- if (tmpret==0) // correct, security key set +- goto out; ++ if (tmpret == SMI_PASSWORD_CORRECT) // correct, security key set ++ return 1; + +- retval = 0; // incorrect password +- if (tmpret==2) +- goto out; ++ if (tmpret == SMI_PASSWORD_INCORRECT) ++ return 0; + } + +- + tmpret = password_installed(which); +- if (tmpret == 0 && tmpret == 2) +- // function succeeded and password not installed +- goto out; +- else if (tmpret == 0) ++ // function succeeded and password not installed ++ if (!(tmpret == 0 || tmpret == 2)) ++ return 2; ++ ++ if (tmpret == 0) + { + tmpret = verify_password(which, password, 0); +- retval = 1; +- if (tmpret==0) // correct, security key set +- goto out; +- retval = 0; // incorrect password +- if (tmpret==2) +- goto out; ++ if (tmpret == SMI_PASSWORD_CORRECT) // correct, security key set ++ return 1; ++ ++ if (tmpret == SMI_PASSWORD_INCORRECT) ++ return 0; + } + +-out: +- return retval; ++ return 2; + } + + int dell_smi_password_format(int which) +-- +2.14.3 + diff --git a/SOURCES/0018-sysinfo_get_asset_tag-get-rid-of-a-strncpy-off-by-on.patch b/SOURCES/0018-sysinfo_get_asset_tag-get-rid-of-a-strncpy-off-by-on.patch new file mode 100644 index 0000000..79f717f --- /dev/null +++ b/SOURCES/0018-sysinfo_get_asset_tag-get-rid-of-a-strncpy-off-by-on.patch @@ -0,0 +1,67 @@ +From dce238da3376ff556e93b892349e5caea4c7c5b5 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 16:36:30 -0400 +Subject: [PATCH 18/22] sysinfo_get_asset_tag(): get rid of a strncpy() off by + one error. + +Covscan found: + +Error: BUFFER_SIZE (CWE-120): [#def39] +libsmbios-2.3.3/src/libsmbios_c/system_info/asset_tag.c:143: buffer_size: Calling strncpy with a source string whose length (13 chars) is greater than or equal to the size argument (13) will fail to null-terminate "assetTag". + +In which case the buffer would not be correctly terminated. This loop +also returns the /first/ zero-length entry instead of trying additional +methods, as the comment at the top implies it should do. + +This patch simplifies the loop, and simply returns +strdup(ASSET_TAG_NOT_SPECIFIED) in the case where we find no useful +response. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/system_info/asset_tag.c | 25 ++++++++++--------------- + 1 file changed, 10 insertions(+), 15 deletions(-) + +diff --git a/src/libsmbios_c/system_info/asset_tag.c b/src/libsmbios_c/system_info/asset_tag.c +index da216b18943..0e865947d41 100644 +--- a/src/libsmbios_c/system_info/asset_tag.c ++++ b/src/libsmbios_c/system_info/asset_tag.c +@@ -128,25 +128,20 @@ LIBSMBIOS_C_DLL_SPEC char *sysinfo_get_asset_tag() + // first function to return non-zero id with strlen()>0 wins. + assetTag = DellAssetTagFunctions[i].f_ptr (); + fnprintf("got result: %p\n", assetTag); +- if (assetTag) ++ if (!assetTag) ++ continue; ++ ++ strip_trailing_whitespace(assetTag); ++ if (!strlen(assetTag)) + { +- strip_trailing_whitespace(assetTag); +- if (!strlen(assetTag)) +- { +- fnprintf("string is zero len, returning as not specified\n"); +- /* +- * In case one of the function returns an empty string (zero len), +- * we would be returning the value "Not Specified" to the caller. +- */ +- assetTag = realloc(assetTag, ASSET_TAG_NOT_SPECIFIED_LEN); +- if (assetTag) +- strncpy(assetTag, ASSET_TAG_NOT_SPECIFIED, ASSET_TAG_NOT_SPECIFIED_LEN - 1); +- goto out; +- } ++ fnprintf("string is zero len, not using it\n"); ++ free(assetTag); ++ assetTag = NULL; + } + } + +-out: ++ if (!assetTag) ++ assetTag = strdup(ASSET_TAG_NOT_SPECIFIED); + return assetTag; + } + +-- +2.14.3 + diff --git a/SOURCES/0019-sysinfo_get_dell_oem_system_id-don-t-look-at-the-wro.patch b/SOURCES/0019-sysinfo_get_dell_oem_system_id-don-t-look-at-the-wro.patch new file mode 100644 index 0000000..a2e7754 --- /dev/null +++ b/SOURCES/0019-sysinfo_get_dell_oem_system_id-don-t-look-at-the-wro.patch @@ -0,0 +1,40 @@ +From f4b6d774fd672c4913384e69ce1f49e448771d6e Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 16:40:44 -0400 +Subject: [PATCH 19/22] sysinfo_get_dell_oem_system_id(): don't look at the + wrong array. + +Covscan noticed: +Error: OVERRUN (CWE-119): [#def40] +libsmbios-2.3.3/src/libsmbios_c/system_info/id_byte.c:219: assignment: Assigning: "numEntries" = "5". +libsmbios-2.3.3/src/libsmbios_c/system_info/id_byte.c:223: cond_at_most: Checking "i < numEntries" implies that "i" may be up to 4 on the true branch. +libsmbios-2.3.3/src/libsmbios_c/system_info/id_byte.c:225: overrun-local: Overrunning array "DellIdByteFunctions" of 4 16-byte elements at element index 4 (byte offset 64) using index "i" (which evaluates to 4). + +What it didn't notice is that DellIdByteFunctions is the wrong array +entirely, which is why it's the wrong offset. It should really notice +that. Oh well. + +Anyway, this patch makes it use the correct array. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/system_info/id_byte.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/libsmbios_c/system_info/id_byte.c b/src/libsmbios_c/system_info/id_byte.c +index 6ea102185a8..52dd3e5a2d6 100644 +--- a/src/libsmbios_c/system_info/id_byte.c ++++ b/src/libsmbios_c/system_info/id_byte.c +@@ -222,7 +222,8 @@ LIBSMBIOS_C_DLL_SPEC int sysinfo_get_dell_oem_system_id() + sysinfo_clearerr(); + for (int i = 0; i < numEntries; ++i) + { +- fnprintf("calling id_byte function: %s\n", DellIdByteFunctions[i].name); ++ fnprintf("calling id_byte function: %s\n", ++ DellOemIdByteFunctions[i].name); + // first function to return non-zero id wins. + systemId = DellOemIdByteFunctions[i].f_ptr (); + +-- +2.14.3 + diff --git a/SOURCES/0020-dell_encode_service_tag-remove-conditionals-that-can.patch b/SOURCES/0020-dell_encode_service_tag-remove-conditionals-that-can.patch new file mode 100644 index 0000000..236223a --- /dev/null +++ b/SOURCES/0020-dell_encode_service_tag-remove-conditionals-that-can.patch @@ -0,0 +1,43 @@ +From acb4b354e5e42d9ddf6b0a84ac3912fa9b53dc11 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 16:45:29 -0400 +Subject: [PATCH 20/22] dell_encode_service_tag(): remove conditionals that + can't be true. + +Covscan noticed: +Error: DEADCODE (CWE-561): [#def41] +libsmbios-2.3.3/src/libsmbios_c/system_info/service_tag.c:109: cond_at_least: Condition "len <= 5UL", taking false branch. Now the value of "len" is at least 6. +libsmbios-2.3.3/src/libsmbios_c/system_info/service_tag.c:122: cond_at_least: Condition "len < 7UL", taking false branch. Now the value of "len" is at least 7. +libsmbios-2.3.3/src/libsmbios_c/system_info/service_tag.c:122: cond_const: Condition "len < 7UL", taking true branch. Now the value of "len" is equal to 6. +libsmbios-2.3.3/src/libsmbios_c/system_info/service_tag.c:149: at_least: At condition "len < 5UL", the value of "len" must be at least 6. +libsmbios-2.3.3/src/libsmbios_c/system_info/service_tag.c:149: dead_error_condition: The condition "len < 5UL" cannot be true. +libsmbios-2.3.3/src/libsmbios_c/system_info/service_tag.c:149: dead_error_line: Execution cannot reach the expression "len" inside this statement: "memcpy(tag, newTagBuf, ((le...". + +And the reason it thinks that is that at the top of the function, we +return: + if (len <= SVC_TAG_CMOS_LEN_MAX) + return; + +So this patch just makes it use that value unconditionally for the memcpy(). + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/system_info/service_tag.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/libsmbios_c/system_info/service_tag.c b/src/libsmbios_c/system_info/service_tag.c +index 353c2314779..b2b0af60eec 100644 +--- a/src/libsmbios_c/system_info/service_tag.c ++++ b/src/libsmbios_c/system_info/service_tag.c +@@ -146,7 +146,7 @@ static void dell_encode_service_tag( char *tag, size_t len ) + newTagBuf[4] = newTagBuf[4] | dell_encode_digit(tagToSet[6]); + + memset(tag, 0, len); +- memcpy(tag, newTagBuf, len < SVC_TAG_CMOS_LEN_MAX ? len: SVC_TAG_CMOS_LEN_MAX); ++ memcpy(tag, newTagBuf, SVC_TAG_CMOS_LEN_MAX); + return; + } + +-- +2.14.3 + diff --git a/SOURCES/0021-token.c-don-t-leak-allocated-token-tables.patch b/SOURCES/0021-token.c-don-t-leak-allocated-token-tables.patch new file mode 100644 index 0000000..cbca59c --- /dev/null +++ b/SOURCES/0021-token.c-don-t-leak-allocated-token-tables.patch @@ -0,0 +1,76 @@ +From bf07436ef6c618487974af59e7044152e065f5e8 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 16:51:11 -0400 +Subject: [PATCH 21/22] token.c: don't leak allocated token tables. + +Covscan noticed: +Error: RESOURCE_LEAK (CWE-772): [#def42] +libsmbios-2.3.3/src/libsmbios_c/token/token.c:41: alloc_fn: Storage is returned from allocation function "token_table_factory". +libsmbios-2.3.3/src/libsmbios_c/token/token_obj.c:84:9: alloc_fn: Storage is returned from allocation function "calloc". +libsmbios-2.3.3/src/libsmbios_c/token/token_obj.c:84:9: var_assign: Assigning: "toReturn" = "calloc(1UL, 32UL)". +libsmbios-2.3.3/src/libsmbios_c/token/token_obj.c:100:9: noescape: Resource "toReturn" is not freed or pointed-to in function "clear_err". +libsmbios-2.3.3/src/libsmbios_c/token/token_obj.c:62:49: noescape: "clear_err(struct token_table const *)" does not free or save its parameter "table". +libsmbios-2.3.3/src/libsmbios_c/token/token_obj.c:101:5: return_alloc: Returning allocated memory "toReturn". +libsmbios-2.3.3/src/libsmbios_c/token/token.c:41: var_assign: Assigning: "table" = storage returned from "token_table_factory(8)". +libsmbios-2.3.3/src/libsmbios_c/token/token.c:44: noescape: Resource "table" is not freed or pointed-to in "token_table_strerror". +libsmbios-2.3.3/src/libsmbios_c/token/token_obj.c:114:61: noescape: "token_table_strerror(struct token_table const *)" does not free or save its parameter "table". +libsmbios-2.3.3/src/libsmbios_c/token/token.c:45: leaked_storage: Variable "table" going out of scope leaks the storage it points to. + +And then I noticed it also happens on some of the generated accessors. + +This patch frees the allocations. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/token/token.c | 31 +++++++++++++++++-------------- + 1 file changed, 17 insertions(+), 14 deletions(-) + +diff --git a/src/libsmbios_c/token/token.c b/src/libsmbios_c/token/token.c +index 296311f25df..0771ca31d2f 100644 +--- a/src/libsmbios_c/token/token.c ++++ b/src/libsmbios_c/token/token.c +@@ -40,24 +40,27 @@ const char * token_strerror() + const char *retval = 0; + struct token_table *table = token_table_factory(TOKEN_DEFAULTS | TOKEN_NO_ERR_CLEAR); + fnprintf("\n"); +- if (table) ++ if (table) { + retval = token_table_strerror(table); ++ free(table); ++ } + return retval; + } + +-#define make_token_fn(ret, defret, callname)\ +- ret token_##callname (u16 id) \ +- {\ +- struct token_table *table = 0; \ +- const struct token_obj *token = 0; \ +- fnprintf("\n"); \ +- table = token_table_factory(TOKEN_DEFAULTS); \ +- if (!table) goto out; \ +- token = token_table_get_next_by_id(table, 0, id); \ +- if (!token) goto out; \ +- return token_obj_##callname (token); \ +-out:\ +- return defret; \ ++#define make_token_fn(ret, defret, callname) \ ++ ret token_##callname (u16 id) \ ++ { \ ++ struct token_table *table = 0; \ ++ const struct token_obj *token = 0; \ ++ fnprintf("\n"); \ ++ table = token_table_factory(TOKEN_DEFAULTS); \ ++ if (!table) goto out; \ ++ token = token_table_get_next_by_id(table, 0, id); \ ++ free(table); \ ++ if (!token) goto out; \ ++ return token_obj_##callname (token); \ ++out: \ ++ return defret; \ + } + + make_token_fn(int, 0, get_type) +-- +2.14.3 + diff --git a/SOURCES/0022-Fix-two-pointer-arithmetic-errors.patch b/SOURCES/0022-Fix-two-pointer-arithmetic-errors.patch new file mode 100644 index 0000000..b78aac6 --- /dev/null +++ b/SOURCES/0022-Fix-two-pointer-arithmetic-errors.patch @@ -0,0 +1,50 @@ +From ea2c72cace1bc67250997c4f8c58fca4f395400d Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Fri, 2 Jun 2017 16:56:37 -0400 +Subject: [PATCH 22/22] Fix two pointer arithmetic errors. + +Covscan noticed: +Error: SIZEOF_MISMATCH (CWE-398): [#def44] +libsmbios-2.3.3/src/libsmbios_c/token/token_d4.c:321: suspicious_pointer_arithmetic: Adding "5UL /* sizeof (*token) */" to pointer "token" of type "struct indexed_io_token *" is suspicious because adding an integral value to this pointer automatically scales that value by the size, 5 bytes, of the pointed-to type, "struct indexed_io_token". Most likely, "sizeof (*token)" is extraneous and should be replaced with 1. + +Error: SIZEOF_MISMATCH (CWE-398): [#def45] +libsmbios-2.3.3/src/libsmbios_c/token/token_da.c:212: suspicious_pointer_arithmetic: Adding "6UL /* sizeof (*token) */" to pointer "token" of type "struct calling_interface_token *" is suspicious because adding an integral value to this pointer automatically scales that value by the size, 6 bytes, of the pointed-to type, "struct calling_interface_token". Most likely, "sizeof (*token)" is extraneous and should be replaced with 1. + +It's right, both of these are checking if they're past the last element, +so 1 should be used. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/token/token_d4.c | 2 +- + src/libsmbios_c/token/token_da.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/libsmbios_c/token/token_d4.c b/src/libsmbios_c/token/token_d4.c +index 6447114ee0a..2659721360a 100644 +--- a/src/libsmbios_c/token/token_d4.c ++++ b/src/libsmbios_c/token/token_d4.c +@@ -318,7 +318,7 @@ int __hidden add_d4_tokens(struct token_table *table) + continue; + } + +- if ( (void* )(token + sizeof(*token) ) > (void *)(d4_struct + d4_struct->length )) ++ if ( (void *)(token + 1) > (void *)(d4_struct + d4_struct->length)) + { + fnprintf("\n"); + fnprintf("\n"); +diff --git a/src/libsmbios_c/token/token_da.c b/src/libsmbios_c/token/token_da.c +index b1832a1aab0..5f80bea9ee1 100644 +--- a/src/libsmbios_c/token/token_da.c ++++ b/src/libsmbios_c/token/token_da.c +@@ -209,7 +209,7 @@ int __hidden add_da_tokens(struct token_table *table) + continue; + } + +- if ( (void* )(token + sizeof(*token) ) > (void *)(da_struct + da_struct->length )) ++ if ( (void *)(token + 1) > (void *)(da_struct + da_struct->length)) + { + fnprintf("\n"); + fnprintf("\n"); +-- +2.14.3 + diff --git a/SOURCES/0023-memory_linux.c-remap-fix-some-types-to-avoid-compari.patch b/SOURCES/0023-memory_linux.c-remap-fix-some-types-to-avoid-compari.patch new file mode 100644 index 0000000..5be0c24 --- /dev/null +++ b/SOURCES/0023-memory_linux.c-remap-fix-some-types-to-avoid-compari.patch @@ -0,0 +1,62 @@ +From 2928a5f3e60a3e9927fbaacde5ddcd5e289eb4b4 Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 14 Feb 2018 13:16:19 -0500 +Subject: [PATCH] memory_linux.c:remap() fix some types to avoid comparison + sign mismatches +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +struct linux_data, remap(), and trycopy() have types that don't have +matching signs for no good reason, and this is noticed if you build with +-Wsign-compare (enabled by the quite wonderful -Wextra in recent gcc). +Right now these are the only thing in the tree that fail with "gcc -Wall +-Wextra -Werror": + +libtool: compile: gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I.. -I./out/include -I./out/include -I../src/include -DLIBSMBIOS_LOCALEDIR=\"/usr/share/locale\" -I../src/libsmbios_c/common -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -fPIC -fvisibility=hidden -Werror -c ../src/libsmbios_c/system_info/system_info.c -fPIC -DPIC -o src/libsmbios_c/system_info/.libs/out_libsmbios_c_la-system_info.o +../src/libsmbios_c/memory/memory_linux.c: In function 'trycopy': +../src/libsmbios_c/memory/memory_linux.c:134:24: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] + if( length + mmoff > (private_data->mappingSize) ) + ^ +and + +libtool: compile: gcc -DHAVE_CONFIG_H -I. -I./out/include -I./out/include -I./src/include -DLIBSMBIOS_LOCALEDIR=\"/usr/local/share/locale\" -I./src/libsmbios_c/common -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -fPIC -fvisibility=hidden -Wall -Werror -Wextra -DLIBSMBIOS_C_ALL_DYN_LINK -MT src/libsmbios_c/memory/out_libsmbios_c_la-memory_linux.lo -MD -MP -MF src/libsmbios_c/memory/.deps/out_libsmbios_c_la-memory_linux.Tpo -c src/libsmbios_c/memory/memory_linux.c -fPIC -DPIC -o src/libsmbios_c/memory/.libs/out_libsmbios_c_la-memory_linux.o +src/libsmbios_c/memory/memory_linux.c: In function ‘remap’: +src/libsmbios_c/memory/memory_linux.c:109:22: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] + if (offset-mmoff == private_data->lastMappedOffset) + ^~ + +This fixes them to use off_t and size_t as appropriate. + +Signed-off-by: Peter Jones +--- + src/libsmbios_c/memory/memory_linux.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/libsmbios_c/memory/memory_linux.c b/src/libsmbios_c/memory/memory_linux.c +index 1d3a46b5adf..f3054bf7ded 100644 +--- a/src/libsmbios_c/memory/memory_linux.c ++++ b/src/libsmbios_c/memory/memory_linux.c +@@ -44,8 +44,8 @@ struct linux_data + int mem_errno; + bool rw; + void *lastMapping; +- u64 lastMappedOffset; +- u64 mappingSize; ++ off_t lastMappedOffset; ++ size_t mappingSize; + }; + + #define READ_MMAP 0 +@@ -98,7 +98,7 @@ static void debug_dump_buffer(const char *fn, const char *s, const u8 *buffer, s + #define debug_dump_buffer(...) do {} while(0) + #endif + +-static void remap(struct linux_data *private_data, u64 offset, bool rw) ++static void remap(struct linux_data *private_data, off_t offset, bool rw) + { + int flags = rw ? PROT_WRITE : PROT_READ; + off_t mmoff = offset % private_data->mappingSize; +-- +2.14.3 + diff --git a/SPECS/libsmbios.spec b/SPECS/libsmbios.spec new file mode 100644 index 0000000..4e406e5 --- /dev/null +++ b/SPECS/libsmbios.spec @@ -0,0 +1,315 @@ +# these are all substituted by autoconf +%define pot_file libsmbios +%define lang_dom libsmbios-2.3 + +# pure python stuff goes here +%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")} + +# arch-dep python stuff goes here +%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")} + +Name: libsmbios +Version: 2.3.3 +Release: 6%{?dist} +License: GPLv2+ or OSL 2.1 +Summary: Libsmbios C/C++ shared libraries +Group: System Environment/Libraries +URL: https://github.com/dell/libsmbios +Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +BuildRequires: strace libxml2-devel gcc-c++ gettext git doxygen +BuildRequires: valgrind cppunit hardlink pkgconfig python-devel +BuildRequires: autoconf gettext-devel automake libtool help2man + +# libsmbios only ever makes sense on intel compatible arches +# no DMI tables on ppc, s390, etc. +ExclusiveArch: x86_64 %{ix86} + +Source0: https://github.com/dell/libsmbios/archive/v%{version}.tar.gz +Patch0001: 0001-Don-t-build-the-yum-plugin.patch +Patch0002: 0002-smbios-utils-bin-make-version-output-parsable-by-hel.patch +Patch0003: 0003-smbios-utils-python-make-version-output-parsable-by-.patch +Patch0004: 0004-Force-python-to-install-to-site-arch-not-site-packag.patch +Patch0005: 0005-Add-stuff-generated-during-the-build-to-.gitignore.patch +Patch0006: 0006-Enable-Wextra-with-some-minor-caveats.patch +Patch0007: 0007-Don-t-compare-signed-and-unsigned-values-in-loop-ite.patch +Patch0008: 0008-Fix-some-missing-error-checks-that-covscan-found.patch +Patch0009: 0009-Check-for-fseek-errors-everywhere.patch +Patch0010: 0010-Fix-a-data-leak-on-the-failure-path.patch +Patch0011: 0011-Fix-an-incorrect-error-check.patch +Patch0012: 0012-Simplify-smbios_table_free-token_table_free-and-cmos.patch +Patch0013: 0013-Fix-a-wrong-conditional.patch +Patch0014: 0014-Fix-a-leaked-file-handle.patch +Patch0015: 0015-Fix-some-plausible-buffer-overruns.patch +Patch0016: 0016-Don-t-leak-smbios_strerror-memory.patch +Patch0017: 0017-Fix-some-impossible-logic.patch +Patch0018: 0018-sysinfo_get_asset_tag-get-rid-of-a-strncpy-off-by-on.patch +Patch0019: 0019-sysinfo_get_dell_oem_system_id-don-t-look-at-the-wro.patch +Patch0020: 0020-dell_encode_service_tag-remove-conditionals-that-can.patch +Patch0021: 0021-token.c-don-t-leak-allocated-token-tables.patch +Patch0022: 0022-Fix-two-pointer-arithmetic-errors.patch +Patch0023: 0023-memory_linux.c-remap-fix-some-types-to-avoid-compari.patch + +%description +Libsmbios is a library and utilities that can be used by client programs to get +information from standard BIOS tables, such as the SMBIOS table. + +This package provides the C-based libsmbios library, with a C interface. + +%package -n python-smbios +Summary: Python interface to Libsmbios C library +Group: System Environment/Libraries +Requires: libsmbios = %{version}-%{release} +Requires: python python-ctypes + +%description -n python-smbios +This package provides a Python interface to libsmbios + +%package -n smbios-utils +Summary: Meta-package that pulls in all smbios binaries and python scripts +Group: Applications/System +Requires: smbios-utils-bin +Requires: smbios-utils-python + +%description -n smbios-utils +This is a meta-package that pulls in the binary libsmbios executables as well +as the python executables. + +%package -n smbios-utils-bin +Summary: Binary utilities that use libsmbios +Group: Applications/System +Requires: libsmbios = %{version}-%{release} + +%description -n smbios-utils-bin +Get BIOS information, such as System product name, product id, service tag and +asset tag. + +%package -n smbios-utils-python +Summary: Python executables that use libsmbios +Group: Applications/System +Requires: python-smbios = %{version}-%{release} + +%description -n smbios-utils-python +Get BIOS information, such as System product name, product id, service tag and +asset tag. Set service and asset tags on Dell machines. Manipulate wireless +cards/bluetooth on Dell laptops. Set BIOS password on select Dell systems. +Update BIOS on select Dell systems. Set LCD brightness on select Dell laptops. + +# name the devel package libsmbios-devel regardless of package name, per suse/fedora convention +%package -n libsmbios-devel +Summary: Development headers and archives +Group: Development/Libraries +Requires: libsmbios = %{version}-%{release} + +%description -n libsmbios-devel +Libsmbios is a library and utilities that can be used by client programs to get +information from standard BIOS tables, such as the SMBIOS table. + +This package contains the headers and .a files necessary to compile new client +programs against libsmbios. + +%prep +%setup -q -n libsmbios-%{version} +find . -type d -exec chmod -f 755 {} \; +find doc src -type f -exec chmod -f 644 {} \; +chmod 755 src/cppunit/*.sh +git init +git config user.email "%{name}-owner@fedoraproject.org" +git config user.name "Fedora Ninjas" +git config gc.auto 0 +git add . +git commit -a -q -m "%{version} baseline." +git am %{patches} configure +chmod +x ./configure + +%configure + +mkdir -p out/libsmbios_c +mkdir -p out/libsmbios_c++ +make CFLAGS="-Werror" %{?_smp_mflags} 2>&1 | tee build-%{_arch}.log + +echo \%doc _build/build-%{_arch}.log > buildlogs.txt + +TOPDIR=$(pwd)/../ +pushd ../src/bin +for x in smbios-battery-ctl smbios-keyboard-ctl smbios-lcd-brightness \ + smbios-passwd smbios-sys-info smbios-thermal-ctl smbios-token-ctl \ + smbios-wakeup-ctl smbios-wireless-ctl ; +do + chmod +x ${x} + LD_LIBRARY_PATH=$TOPDIR/_build/out/.libs/ help2man -o ${x}.8 -s 8 -n ${x} -N -l ./${x} +done +popd +pushd out +for x in smbios-get-ut-data smbios-state-byte-ctl smbios-sys-info-lite \ + smbios-upflag-ctl ; +do + LD_LIBRARY_PATH=$TOPDIR/_build/out/.libs/ help2man -o ${x}.8 -s 8 -n ${x} -N -l ./${x} +done +popd + + +%check +runtest() { + mkdir _$1$2 + pushd _$1$2 + ../configure + make -e $1 CFLAGS="$CFLAGS -DDEBUG_OUTPUT_ALL" 2>&1 | tee $1$2.log + touch -r ../configure.ac $1$2-%{_arch}.log + make -e $1 2>&1 | tee $1$2.log + popd + echo \%doc _$1$2/$1$2-%{_arch}.log >> _build/buildlogs.txt +} + +if [ -d /usr/include/cppunit ]; then + # run this first since it is slightly faster than valgrind + VALGRIND="strace -f" runtest check strace > /dev/null || echo FAILED strace check +fi + +if [ -e /usr/bin/valgrind -a -d /usr/include/cppunit ]; then + runtest valgrind > /dev/null || echo FAILED valgrind check +fi + +if [ -d /usr/include/cppunit ]; then + runtest check > /dev/null || echo FAILED check +fi + +if [ ! -d /usr/include/cppunit ]; then + echo "Unit tests skipped due to missing cppunit." +fi + +%install +rm -rf %{buildroot} +mkdir %{buildroot} + +cd _build +TOPDIR=.. +make install DESTDIR=%{buildroot} INSTALL="%{__install} -p" +mkdir -p %{buildroot}/%{_includedir} +mkdir -p %{buildroot}/%{_bindir} +mkdir -p %{buildroot}/%{_mandir}/man8/ +cp -v $TOPDIR/src/bin/*.8 %{buildroot}/%{_mandir}/man8/ +cp -v $TOPDIR/_build/out/*.8 %{buildroot}/%{_mandir}/man8/ +cp -a $TOPDIR/src/include/* %{buildroot}/%{_includedir}/ +cp -a out/public-include/* %{buildroot}/%{_includedir}/ +rm -f %{buildroot}/%{_libdir}/lib*.{la,a} +find %{buildroot}/%{_includedir} out/libsmbios_c++ out/libsmbios_c -exec touch -r $TOPDIR/configure.ac {} \; + +mv out/libsmbios_c++ out/libsmbios_c++-%{_arch} +mv out/libsmbios_c out/libsmbios_c-%{_arch} + +rename %{pot_file}.mo %{lang_dom}.mo $(find %{buildroot}/%{_datadir} -name %{pot_file}.mo) +%find_lang %{lang_dom} + +# hardlink files to save some space. +/usr/sbin/hardlink -c -v $RPM_BUILD_ROOT + +%clean +rm -rf %{buildroot} + +%post -p /sbin/ldconfig +%postun -p /sbin/ldconfig + +%files -f _build/%{lang_dom}.lang +%defattr(-,root,root,-) +%{_libdir}/libsmbios_c.so.* + +%files -n libsmbios-devel -f _build/buildlogs.txt +%defattr(-,root,root,-) +%doc COPYING-GPL COPYING-OSL README.md src/bin/getopts_LICENSE.txt src/include/smbios/config/boost_LICENSE_1_0_txt +%{_includedir}/smbios +%{_includedir}/smbios_c +%{_libdir}/libsmbios_c.so +%{_libdir}/pkgconfig/*.pc +%doc _build/out/libsmbios_c-%{_arch} + +%files -n smbios-utils +# opensuse 11.1 enforces non-empty file list :( +%defattr(-,root,root,-) +%doc COPYING-GPL COPYING-OSL README.md +# no other files. + +%files -n smbios-utils-bin +%defattr(-,root,root,-) +%doc COPYING-GPL COPYING-OSL README.md +%doc src/bin/getopts_LICENSE.txt src/include/smbios/config/boost_LICENSE_1_0_txt +%{_sbindir}/smbios-state-byte-ctl +%{_mandir}/man8/smbios-state-byte-ctl.* +%{_sbindir}/smbios-get-ut-data +%{_mandir}/man8/smbios-get-ut-data.* +%{_sbindir}/smbios-upflag-ctl +%{_mandir}/man8/smbios-upflag-ctl.* +%{_sbindir}/smbios-sys-info-lite +%{_mandir}/man8/smbios-sys-info-lite.* + +%files -n python-smbios +%defattr(-,root,root,-) +%doc COPYING-GPL COPYING-OSL README.md +%{python_sitearch}/* + +%files -n smbios-utils-python +%defattr(-,root,root,-) +%doc COPYING-GPL COPYING-OSL README.md +%doc src/bin/getopts_LICENSE.txt src/include/smbios/config/boost_LICENSE_1_0_txt +%dir %{_sysconfdir}/libsmbios +%config(noreplace) %{_sysconfdir}/libsmbios/* + +# python utilities +%{_sbindir}/smbios-battery-ctl +%{_mandir}/man8/smbios-battery-ctl.* +%{_sbindir}/smbios-sys-info +%{_mandir}/man8/smbios-sys-info.* +%{_sbindir}/smbios-token-ctl +%{_mandir}/man8/smbios-token-ctl.* +%{_sbindir}/smbios-passwd +%{_mandir}/man8/smbios-passwd.* +%{_sbindir}/smbios-wakeup-ctl +%{_mandir}/man8/smbios-wakeup-ctl.* +%{_sbindir}/smbios-wireless-ctl +%{_mandir}/man8/smbios-wireless-ctl.* +%{_sbindir}/smbios-lcd-brightness +%{_mandir}/man8/smbios-lcd-brightness.* +%{_sbindir}/smbios-keyboard-ctl +%{_mandir}/man8/smbios-keyboard-ctl.* +%{_sbindir}/smbios-thermal-ctl +%{_mandir}/man8/smbios-thermal-ctl.* + +# data files +%{_datadir}/smbios-utils + +%changelog +* Wed Feb 14 2018 Peter Jones - 2.3.3-6 +- Pull in all the coverity fixes we sent upstream. I had thought these + made it in to this release; they did not, but the 2.4.0 release they are + in is also the python 3 switchover, so we need these as patches. + Related: rhbz#1463329 + +* Tue Feb 13 2018 Peter Jones - 2.3.3-5 +- Try once more to fix the multilib issue... + Related: rhbz#1463329 + +* Fri Feb 09 2018 Peter Jones - 2.3.3-4 +- Fix a multilib error rpmdiff caught + Related: rhbz#1463329 + +* Thu Oct 05 2017 Peter Jones - 2.3.3-3 +- Fix some more rpmdiff complaints + Related: rhbz#1463329 + +* Thu Oct 05 2017 Peter Jones - 2.3.3-2 +- Fix some rpmdiff complaints + Related: rhbz#1463329 + +* Mon Oct 02 2017 Peter Jones - 2.3.3-1 +- Package 2.3.3 + Related: rhbz#1463329