Backport upstream Coverity fixes; Do not build ccache-swig on RHEL

This commit is contained in:
Jitka Plesnikova 2018-04-25 09:20:36 +02:00
parent 9d7264020b
commit 54392e7afe
7 changed files with 258 additions and 24 deletions

View File

@ -0,0 +1,58 @@
From 21f532975f59f0c156c76cc739f5a93f57d8f6cb Mon Sep 17 00:00:00 2001
From: Mark Dufour <m.dufour@kopano.com>
Date: Tue, 14 Feb 2017 10:48:30 +0100
Subject: [PATCH] [Coverity] fix issue reported for
SWIG_Python_ConvertFunctionPtr
Fix Coverity issue reported for SWIG_Python_ConvertFunctionPtr:
"Execution cannot reach this statement: *ptr = vptr;"
Because if 'ty' is null, then desc becomes null and we return with
SWIG_ERROR. So 'ty' cannot be null at 'if (ty)'.
---
Lib/python/pyrun.swg | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index ab1237f62..939a69204 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -1287,25 +1287,22 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) {
return SWIG_ConvertPtr(obj, ptr, ty, 0);
} else {
void *vptr = 0;
-
+ swig_cast_info *tc;
+
/* here we get the method pointer for callbacks */
const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);
const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0;
if (desc)
desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0;
- if (!desc)
+ if (!desc)
return SWIG_ERROR;
- if (ty) {
- swig_cast_info *tc = SWIG_TypeCheck(desc,ty);
- if (tc) {
- int newmemory = 0;
- *ptr = SWIG_TypeCast(tc,vptr,&newmemory);
- assert(!newmemory); /* newmemory handling not yet implemented */
- } else {
- return SWIG_ERROR;
- }
+ tc = SWIG_TypeCheck(desc,ty);
+ if (tc) {
+ int newmemory = 0;
+ *ptr = SWIG_TypeCast(tc,vptr,&newmemory);
+ assert(!newmemory); /* newmemory handling not yet implemented */
} else {
- *ptr = vptr;
+ return SWIG_ERROR;
}
return SWIG_OK;
}
--
2.14.3

View File

@ -0,0 +1,36 @@
From 9825fcbab5c4ddd867432f9922bebfbec7b78af0 Mon Sep 17 00:00:00 2001
From: Mark Dufour <m.dufour@kopano.com>
Date: Tue, 14 Feb 2017 10:34:37 +0100
Subject: [PATCH] [Coverity] fix issue reported for SWIG_Python_FixMethods
Fix Coverity issue reported for SWIG_Python_FixMethods:
"buffer_size: Calling strncpy with a source string whose length
(10 chars) is greater than or equal to the size argument (10)
will fail to null-terminate buff."
The issue is only reported for the "swig_ptr: " line, but for
consistency we replace both occurrences of strncpy with memcpy.
---
Lib/python/pyinit.swg | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg
index 2cc582841..fe45ac941 100644
--- a/Lib/python/pyinit.swg
+++ b/Lib/python/pyinit.swg
@@ -306,9 +306,9 @@ SWIG_Python_FixMethods(PyMethodDef *methods,
char *ndoc = (char*)malloc(ldoc + lptr + 10);
if (ndoc) {
char *buff = ndoc;
- strncpy(buff, methods[i].ml_doc, ldoc);
+ memcpy(buff, methods[i].ml_doc, ldoc);
buff += ldoc;
- strncpy(buff, "swig_ptr: ", 10);
+ memcpy(buff, "swig_ptr: ", 10);
buff += 10;
SWIG_PackVoidPtr(buff, ptr, ty->name, lptr);
methods[i].ml_doc = ndoc;
--
2.14.3

View File

@ -0,0 +1,41 @@
From 13eeebd2fb3005abc876957c68bde6a92510aa44 Mon Sep 17 00:00:00 2001
From: Mark Dufour <m.dufour@kopano.com>
Date: Tue, 14 Feb 2017 10:53:14 +0100
Subject: [PATCH] [Coverity] fix issue reported for wrapper argument checking
Fix Coverity issue reported for wrapper argument checking:
"Null-checking args suggests that it may be null, but it has already
been dereferenced on all paths leading to the check."
So 'args' is null checked, but after dereferencing it with
PyTuple_Check(args).
---
Source/Modules/python.cxx | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index a6801fc4e..5e058e773 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -2541,9 +2541,14 @@ public:
if (!fastunpack) {
Wrapper_add_local(f, "ii", "Py_ssize_t ii");
- if (maxargs - (add_self ? 1 : 0) > 0)
- Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
- Append(f->code, "argc = args ? PyObject_Length(args) : 0;\n");
+
+ if (maxargs - (add_self ? 1 : 0) > 0) {
+ Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
+ Append(f->code, "argc = PyObject_Length(args);\n");
+ } else {
+ Append(f->code, "argc = args ? PyObject_Length(args) : 0;\n");
+ }
+
if (add_self)
Append(f->code, "argv[0] = self;\n");
Printf(f->code, "for (ii = 0; (ii < %d) && (ii < argc); ii++) {\n", add_self ? maxargs - 1 : maxargs);
--
2.14.3

View File

@ -0,0 +1,40 @@
From 5803e81d488e97623fe29b8629b977be01a8229e Mon Sep 17 00:00:00 2001
From: Mark Dufour <m.dufour@kopano.com>
Date: Mon, 6 Mar 2017 21:16:41 +0100
Subject: [PATCH] Fix Coverity issue reported for setslice (pycontainer.swg):
"CID 11151 (#3-1 of 3): Using invalid iterator (INVALIDATE_ITERATOR)18.
increment_iterator: Incrementing iterator it though it is already past
the end of its container."
Coverity does not understand 'replace_count', so warns that we may go
past self->end() (or self->rend() I guess).
---
Lib/python/pycontainer.swg | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg
index d40b0baa8..9aefb4fc7 100644
--- a/Lib/python/pycontainer.swg
+++ b/Lib/python/pycontainer.swg
@@ -351,7 +351,7 @@ namespace swig {
typename Sequence::const_iterator isit = is.begin();
typename Sequence::iterator it = self->begin();
std::advance(it,ii);
- for (size_t rc=0; rc<replacecount; ++rc) {
+ for (size_t rc=0; rc<replacecount && it != self->end(); ++rc) {
*it++ = *isit++;
for (Py_ssize_t c=0; c<(step-1) && it != self->end(); ++c)
it++;
@@ -367,7 +367,7 @@ namespace swig {
typename Sequence::const_iterator isit = is.begin();
typename Sequence::reverse_iterator it = self->rbegin();
std::advance(it,size-ii-1);
- for (size_t rc=0; rc<replacecount; ++rc) {
+ for (size_t rc=0; rc<replacecount && it != self->rend(); ++rc) {
*it++ = *isit++;
for (Py_ssize_t c=0; c<(-step-1) && it != self->rend(); ++c)
it++;
--
2.14.3

View File

@ -1,21 +0,0 @@
diff -up swig-3.0.12/configure.ac.go110 swig-3.0.12/configure.ac
--- swig-3.0.12/configure.ac.go110 2018-02-13 13:08:16.543632561 +0100
+++ swig-3.0.12/configure.ac 2018-02-13 13:56:20.241295155 +0100
@@ -2606,7 +2606,7 @@ else
esac
AC_MSG_CHECKING([whether go version is too old])
case $go_version in
- go1.1* | go1.0* | go1 )
+ go1.1 | go1.0* | go1 )
AC_MSG_RESULT([yes - minimum version is 1.2])
GO=
GOOPT="-intgosize 32"
@@ -2624,7 +2624,7 @@ else
;;
esac
case $go_version in
- go1.0* | go1 | go1.1*)
+ go1.0* | go1 | go1.1)
GOOPT="$GOOPT -use-shlib"
;;
go1.2*)

View File

@ -0,0 +1,51 @@
From 5f6012039abb6ec9e9dfea801effa6b02fd102bc Mon Sep 17 00:00:00 2001
From: Vsevolod Kvachev <rasielll@gmail.com>
Date: Thu, 19 Apr 2018 23:04:37 +0300
Subject: [PATCH] Fix go version matching in configure for go1.10
---
configure.ac | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/configure.ac b/configure.ac
index 833cb37bf..ba1631743 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2597,7 +2597,7 @@ else
GOVERSIONOPTION=version
go_version=$($GO $GOVERSIONOPTION | sed -e 's/go version //')
case "$go_version" in
- go1 | go1.[[01234]]*)
+ go1 | go1.[[01234]] | go1.[[01234]].*)
GOC=$(sh -c "$(go env) && echo \$GOCHAR")c
;;
*)
@@ -2606,7 +2606,7 @@ else
esac
AC_MSG_CHECKING([whether go version is too old])
case $go_version in
- go1.1* | go1.0* | go1 )
+ go1.1.* | go1.1 | go1.0 | go1.0.* | go1 )
AC_MSG_RESULT([yes - minimum version is 1.2])
GO=
GOOPT="-intgosize 32"
@@ -2624,13 +2624,13 @@ else
;;
esac
case $go_version in
- go1.0* | go1 | go1.1*)
+ go1.0 | go1.0.* | go1 | go1.1 | go1.1.*)
GOOPT="$GOOPT -use-shlib"
;;
- go1.2*)
+ go1.2 | go1.2.*)
GO12=true
;;
- go1.3* | go1.4*)
+ go1.3 | go1.3.* | go1.4 | go1.4.*)
GO13=true
;;
*)
--
2.14.3

View File

@ -12,9 +12,11 @@
%{!?golang:%global golang 0}
%{!?octave:%global octave 0}
%{!?Rlang:%global Rlang 0}
%bcond_with build_ccache_swig
%else
%{!?octave:%global octave 1}
%{!?Rlang:%global Rlang 1}
%bcond_without build_ccache_swig
%endif
%ifarch aarch64 %{arm} %{mips} ppc64le ppc %{power64} s390 s390x
%{!?javalang:%global javalang 0}
@ -31,15 +33,17 @@
Summary: Connects C/C++/Objective C to some high-level programming languages
Name: swig
Version: 3.0.12
Release: 16%{?dist}
Release: 17%{?dist}
License: GPLv3+ and BSD
URL: http://swig.sourceforge.net/
Source0: http://downloads.sourceforge.net/project/swig/swig/swig-%{version}/swig-%{version}.tar.gz
# Define the part of man page sections
Source1: description.h2m
%if %{with build_ccache_swig}
Source2: description-ccache.h2m
Source3: ccache-swig.sh
Source4: ccache-swig.csh
%endif
Patch0: swig308-Do-not-use-isystem.patch
Patch1: swig-3.0.12-Fix-testsuite-to-work-without-.-in-INC.patch
@ -50,7 +54,12 @@ Patch2: https://patch-diff.githubusercontent.com/raw/swig/swig/pull/968/swig-no
Patch3: swig-3.0.12-Fix-generated-code-for-constant-expressions-containi.patch
Patch4: swig-3.0.12-Fix-type-promotion-wrapping-some-non-trivial-constan.patch
Patch5: swig-3.0.12-Correct-php-testcase.patch
Patch6: swig-3.0.12-Fix-configure-for-Go-1_10.patch
Patch6: swig-3.0.12-Fix-go-version-matching-in-configure-for-go1.10.patch
# Backport upstream Coverity fixes (BZ# 1570037)
Patch7: swig-3.0.12-Coverity-fix-issue-reported-for-SWIG_Python_FixMetho.patch
Patch8: swig-3.0.12-Fix-Coverity-issue-reported-for-setslice-pycontainer.patch
Patch9: swig-3.0.12-Coverity-fix-issue-reported-for-wrapper-argument-che.patch
Patch10: swig-3.0.12-Coverity-fix-issue-reported-for-SWIG_Python_ConvertF.patch
BuildRequires: perl-interpreter, pcre-devel
BuildRequires: python2-devel, python3-devel
@ -110,11 +119,11 @@ Eiffel and Guile. SWIG is normally used to create high-level
interpreted programming environments, systems integration, and as a
tool for building user interfaces
%if %{with build_ccache_swig}
%package -n ccache-swig
Summary: Fast compiler cache
License: GPLv2+
Group: Development/Tools
Requires: ccache
Requires: swig
Conflicts: swig < 3.0.8-2
@ -122,6 +131,7 @@ Conflicts: swig < 3.0.8-2
ccache-swig is a compiler cache. It speeds up re-compilation of C/C++/SWIG
code by caching previous compiles and detecting when the same compile is
being done again. ccache-swig is ccache plus support for SWIG.
%endif
%package doc
Summary: Documentation files for SWIG
@ -151,6 +161,10 @@ in gdb.
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
for all in CHANGES README; do
iconv -f ISO88591 -t UTF8 < $all > $all.new
@ -182,6 +196,9 @@ done
--with-octave=/usr/bin/octave \
--without-maximum-compile-warnings \
%endif
%if %{without build_ccache_swig}
--disable-ccache \
%endif
;
make %{?_smp_mflags}
@ -231,6 +248,7 @@ chmod a+x h2m_helper_swig
# Generate man page
help2man -N --section 1 ./h2m_helper_swig --include %{SOURCE1} -o %{name}.1
%if %{with build_ccache_swig}
########################################################
# Use help output for generating of man page ccache-swig
%{buildroot}%{_bindir}/ccache-swig -h >>help_ccache
@ -257,19 +275,24 @@ sed -i -e 's#@DOCDIR@#%{_docdir}#' help_ccache
# Generate man page
help2man -N --section 1 ./h2m_helper_ccache --include help_ccache -o ccache-swig.1
%endif
# Add man page for swig to repository
mkdir -p %{buildroot}%{_mandir}/man1/
install -p -m 0644 %{name}.1 %{buildroot}%{_mandir}/man1/
%if %{with build_ccache_swig}
install -p -m 0644 ccache-swig.1 %{buildroot}%{_mandir}/man1/
%endif
# Quiet some rpmlint complaints - remove empty file
rm -f %{buildroot}%{_datadir}/%name/%{version}/octave/std_carray.i
%if %{with build_ccache_swig}
# Enable ccache-swig by default
mkdir -p %{buildroot}%{_sysconfdir}/profile.d/
install -dm 755 %{buildroot}%{_sysconfdir}/profile.d
install -pm 644 %{SOURCE3} %{SOURCE4} %{buildroot}%{_sysconfdir}/profile.d
%endif
# Add swig.gdb sub-package gdb
mkdir -p %{buildroot}%{_datadir}/%{name}/gdb
@ -284,10 +307,12 @@ install -pm 644 Tools/swig.gdb %{buildroot}%{_datadir}/%{name}/gdb
%doc ANNOUNCE CHANGES CHANGES.current
%doc COPYRIGHT README TODO
%if %{with build_ccache_swig}
%files -n ccache-swig
%{_bindir}/ccache-swig
%config(noreplace) %{_sysconfdir}/profile.d/ccache-swig.*sh
%{_mandir}/man1/ccache-swig.1*
%endif
%files doc
%license LICENSE LICENSE-GPL LICENSE-UNIVERSITIES
@ -297,6 +322,10 @@ install -pm 644 Tools/swig.gdb %{buildroot}%{_datadir}/%{name}/gdb
%{_datadir}/%{name}/gdb
%changelog
* Tue Apr 24 2018 Jitka Plesnikova <jplesnik@redhat.com> - 3.0.12-17
- Backport upstream Coverity fixes (bug#1570037)
- Do not build ccache-swig on RHEL
* Wed Feb 14 2018 Jitka Plesnikova <jplesnik@redhat.com> - 3.0.12-16
- Update conditions for tests
- Fix configure to properly check version of Go 1.10