- Fix aligned alloc parameters and overflow on 32bit (#1497458)

This commit is contained in:
Brian C. Lane 2017-10-03 10:58:53 -07:00
parent b432b77964
commit 4390d41ad0
2 changed files with 80 additions and 2 deletions

View File

@ -0,0 +1,73 @@
From 64c71d7fc28c32ea61bf155bf1503646e4b1bf72 Mon Sep 17 00:00:00 2001
From: squimrel <squimrel@users.noreply.github.com>
Date: Wed, 23 Aug 2017 04:21:14 +0000
Subject: [PATCH] Fix aligned alloc parameters and overflow on 32bit size_t
(cherry picked from commit f802c54f736006566041aeb6a9d741a6d83ce687)
---
libcheckisomd5.c | 3 ++-
libimplantisomd5.c | 3 ++-
utilities.c | 4 ++--
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/libcheckisomd5.c b/libcheckisomd5.c
index b190959..3ec3d88 100644
--- a/libcheckisomd5.c
+++ b/libcheckisomd5.c
@@ -49,6 +49,7 @@ static enum isomd5sum_status checkmd5sum(int isofd, checkCallback cb, void *cbda
return ISOMD5SUM_CHECK_NOT_FOUND;
const off_t total_size = info->isosize - info->skipsectors * SECTOR_SIZE;
+ const off_t fragment_size = total_size / (info->fragmentcount + 1);
if (cb)
cb(cbdata, 0, total_size);
@@ -85,7 +86,7 @@ static enum isomd5sum_status checkmd5sum(int isofd, checkCallback cb, void *cbda
MD5_Update(&hashctx, buffer, (unsigned int) nread);
if (info->fragmentcount) {
- const size_t current_fragment = (size_t)(offset * (off_t)(info->fragmentcount + 1) / total_size);
+ const size_t current_fragment = offset / fragment_size;
const size_t fragmentsize = FRAGMENT_SUM_SIZE / info->fragmentcount;
/* If we're onto the next fragment, calculate the previous sum and check. */
if (current_fragment != previous_fragment) {
diff --git a/libimplantisomd5.c b/libimplantisomd5.c
index 53801c8..47f21d7 100644
--- a/libimplantisomd5.c
+++ b/libimplantisomd5.c
@@ -106,6 +106,7 @@ int implantISOFD(int isofd, int supported, int forceit, int quiet, char **errstr
buffer = aligned_alloc(pagesize, buffer_size * sizeof(*buffer));
const off_t total_size = isosize - SKIPSECTORS * SECTOR_SIZE;
+ const off_t fragment_size = total_size / (FRAGMENT_COUNT + 1);
size_t previous_fragment = 0UL;
off_t offset = 0LL;
while (offset < total_size) {
@@ -115,7 +116,7 @@ int implantISOFD(int isofd, int supported, int forceit, int quiet, char **errstr
break;
MD5_Update(&hashctx, buffer, (unsigned int) nread);
- const size_t current_fragment = (size_t) offset * (FRAGMENT_COUNT + 1) / (size_t) total_size;
+ const size_t current_fragment = offset / fragment_size;
const size_t fragmentsize = FRAGMENT_SUM_SIZE / FRAGMENT_COUNT;
/* If we're onto the next fragment, calculate the previous sum and check. */
if (current_fragment != previous_fragment) {
diff --git a/utilities.c b/utilities.c
index b00337f..cfa84ed 100644
--- a/utilities.c
+++ b/utilities.c
@@ -131,9 +131,9 @@ struct volume_info *const parsepvd(const int isofd) {
buffer[APPDATA_SIZE - 1] = '\0';
struct volume_info *result = malloc(sizeof(struct volume_info));
- result->skipsectors = 20;
+ result->skipsectors = SKIPSECTORS;
result->supported = 0;
- result->fragmentcount = 20;
+ result->fragmentcount = FRAGMENT_COUNT;
result->offset = offset;
result->isosize = isosize(aligned_buffer);
--
2.13.5

View File

@ -1,7 +1,7 @@
Summary: Utilities for working with md5sum implanted in ISO images
Name: isomd5sum
Version: 1.2.1
Release: 3%{?dist}
Release: 4%{?dist}
Epoch: 1
License: GPLv2+
Group: Applications/System
@ -9,6 +9,8 @@ Group: Applications/System
Url: https://github.com/rhinstaller/isomd5sum
Source0: https://github.com/rhinstaller/%{name}/archive/%{version}.tar.gz
Patch0: 0001-Fix-aligned-alloc-parameters-and-overflow-on-32bit-s.patch
BuildRequires: popt-devel
BuildRequires: python2-devel python3-devel
@ -43,7 +45,7 @@ an md5sum implanted into an ISO9660 image.
%prep
%setup -q
%autosetup
rm -rf %{py3dir}
cp -a . %{py3dir}
@ -80,6 +82,9 @@ popd
%{python3_sitearch}/pyisomd5sum.so
%changelog
* Tue Oct 03 2017 Brian C. Lane <bcl@redhat.com> - 1.2.1-4
- Fix aligned alloc parameters and overflow on 32bit (#1497458)
* Wed Aug 02 2017 Fedora Release Engineering <releng@fedoraproject.org> - 1:1.2.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild