Fixes due to compiler checks for possible truncation by snprintf.
This commit is contained in:
parent
b3bd2d418d
commit
c307e8c48d
85
libpfm-truncation.patch
Normal file
85
libpfm-truncation.patch
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
diff --git a/lib/pfmlib_perf_event_pmu.c b/lib/pfmlib_perf_event_pmu.c
|
||||||
|
index 86ff824..ca371d8 100644
|
||||||
|
--- a/lib/pfmlib_perf_event_pmu.c
|
||||||
|
+++ b/lib/pfmlib_perf_event_pmu.c
|
||||||
|
@@ -344,6 +344,7 @@ gen_tracepoint_table(void)
|
||||||
|
|
||||||
|
err = 0;
|
||||||
|
while((d1 = readdir(dir1)) && err >= 0) {
|
||||||
|
+ int retlen;
|
||||||
|
|
||||||
|
if (!strcmp(d1->d_name, "."))
|
||||||
|
continue;
|
||||||
|
@@ -351,7 +352,10 @@ gen_tracepoint_table(void)
|
||||||
|
if (!strcmp(d1->d_name, ".."))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
- snprintf(d2path, MAXPATHLEN, "%s/%s", debugfs_mnt, d1->d_name);
|
||||||
|
+ retlen = snprintf(d2path, MAXPATHLEN, "%s/%s", debugfs_mnt, d1->d_name);
|
||||||
|
+ /* if string truncated do not try to open the corrupted path */
|
||||||
|
+ if (retlen < 0 || retlen >= MAXPATHLEN)
|
||||||
|
+ continue;
|
||||||
|
|
||||||
|
/* fails if d2path is not a directory */
|
||||||
|
dir2 = opendir(d2path);
|
||||||
|
@@ -398,10 +402,16 @@ gen_tracepoint_table(void)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
#ifdef HAS_OPENAT
|
||||||
|
- snprintf(idpath, MAXPATHLEN, "%s/id", d2->d_name);
|
||||||
|
+ retlen = snprintf(idpath, MAXPATHLEN, "%s/id", d2->d_name);
|
||||||
|
+ /* if string truncated do not try to open the corrupted path */
|
||||||
|
+ if (retlen < 0 || retlen >= MAXPATHLEN)
|
||||||
|
+ continue;
|
||||||
|
fd = openat(dir2_fd, idpath, O_RDONLY);
|
||||||
|
#else
|
||||||
|
- snprintf(idpath, MAXPATHLEN, "%s/%s/id", d2path, d2->d_name);
|
||||||
|
+ retlen = snprintf(idpath, MAXPATHLEN, "%s/%s/id", d2path, d2->d_name);
|
||||||
|
+ /* if string truncated do not try to open the corrupted path */
|
||||||
|
+ if (retlen < 0 || retlen >= MAXPATHLEN)
|
||||||
|
+ continue;
|
||||||
|
fd = open(idpath, O_RDONLY);
|
||||||
|
#endif
|
||||||
|
if (fd == -1)
|
||||||
|
diff --git a/perf_examples/syst_count.c b/perf_examples/syst_count.c
|
||||||
|
index e0fa42e..7841d01 100644
|
||||||
|
--- a/perf_examples/syst_count.c
|
||||||
|
+++ b/perf_examples/syst_count.c
|
||||||
|
@@ -112,12 +112,14 @@ open_cgroup(char *name)
|
||||||
|
{
|
||||||
|
char path[MAX_PATH+1];
|
||||||
|
char mnt[MAX_PATH+1];
|
||||||
|
- int cfd;
|
||||||
|
+ int cfd, retlen;
|
||||||
|
|
||||||
|
if (cgroupfs_find_mountpoint(mnt, MAX_PATH+1))
|
||||||
|
errx(1, "cannot find cgroup fs mount point");
|
||||||
|
|
||||||
|
- snprintf(path, MAX_PATH, "%s/%s", mnt, name);
|
||||||
|
+ retlen = snprintf(path, MAX_PATH, "%s/%s", mnt, name);
|
||||||
|
+ if (retlen < 0 || retlen >= MAX_PATH)
|
||||||
|
+ warn("path truncated %s/%s\n", mnt, name);
|
||||||
|
|
||||||
|
cfd = open(path, O_RDONLY);
|
||||||
|
if (cfd == -1)
|
||||||
|
diff --git a/perf_examples/syst_smpl.c b/perf_examples/syst_smpl.c
|
||||||
|
index 6b70e0e..a8b00df 100755
|
||||||
|
--- a/perf_examples/syst_smpl.c
|
||||||
|
+++ b/perf_examples/syst_smpl.c
|
||||||
|
@@ -278,12 +278,14 @@ open_cgroup(char *name)
|
||||||
|
{
|
||||||
|
char path[MAX_PATH+1];
|
||||||
|
char mnt[MAX_PATH+1];
|
||||||
|
- int cfd;
|
||||||
|
+ int cfd, retlen;
|
||||||
|
|
||||||
|
if (cgroupfs_find_mountpoint(mnt, MAX_PATH+1))
|
||||||
|
errx(1, "cannot find cgroup fs mount point");
|
||||||
|
|
||||||
|
- snprintf(path, MAX_PATH, "%s/%s", mnt, name);
|
||||||
|
+ retlen = snprintf(path, MAX_PATH, "%s/%s", mnt, name);
|
||||||
|
+ if (retlen < 0 || retlen >= MAX_PATH)
|
||||||
|
+ warn("path truncated %s/%s\n", mnt, name);
|
||||||
|
|
||||||
|
cfd = open(path, O_RDONLY);
|
||||||
|
if (cfd == -1)
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
Name: libpfm
|
Name: libpfm
|
||||||
Version: 4.9.0
|
Version: 4.9.0
|
||||||
Release: 3%{?dist}
|
Release: 4%{?dist}
|
||||||
|
|
||||||
Summary: Library to encode performance events for use by perf tool
|
Summary: Library to encode performance events for use by perf tool
|
||||||
|
|
||||||
@ -18,6 +18,7 @@ Group: System Environment/Libraries
|
|||||||
License: MIT
|
License: MIT
|
||||||
URL: http://perfmon2.sourceforge.net/
|
URL: http://perfmon2.sourceforge.net/
|
||||||
Source0: http://sourceforge.net/projects/perfmon2/files/libpfm4/%{name}-%{version}.tar.gz
|
Source0: http://sourceforge.net/projects/perfmon2/files/libpfm4/%{name}-%{version}.tar.gz
|
||||||
|
Patch1: libpfm-truncation.patch
|
||||||
|
|
||||||
%if %{with python}
|
%if %{with python}
|
||||||
BuildRequires: python2-devel
|
BuildRequires: python2-devel
|
||||||
@ -66,6 +67,7 @@ Python bindings for libpfm4 and perf_event_open system call.
|
|||||||
|
|
||||||
%prep
|
%prep
|
||||||
%setup -q
|
%setup -q
|
||||||
|
%patch1 -p1 -b .trun
|
||||||
|
|
||||||
%build
|
%build
|
||||||
%if %{with python}
|
%if %{with python}
|
||||||
@ -114,6 +116,9 @@ make \
|
|||||||
%endif
|
%endif
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Jan 30 2018 William Cohen <wcohen@redhat.com> - 4.9.0-4
|
||||||
|
- Address truncation issues.
|
||||||
|
|
||||||
* Tue Jan 30 2018 William Cohen <wcohen@redhat.com> - 4.9.0-3
|
* Tue Jan 30 2018 William Cohen <wcohen@redhat.com> - 4.9.0-3
|
||||||
- Use the RPM build flags. (RHBZ #1540262)
|
- Use the RPM build flags. (RHBZ #1540262)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user