[hivex/f21] Don't leak errno E2BIG to callers.

Richard W.M. Jones rjones at fedoraproject.org
Tue Nov 25 09:48:00 UTC 2014


commit 1f56eca3bcf63959c76ee821a0c5a4eddfb21401
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Thu Nov 20 21:41:08 2014 +0000

    Don't leak errno E2BIG to callers.
    
    (cherry picked from commit 4604a1d345f0b9e075bfdb679f592b306c64681a)

 ...-t-leak-errno-from-_hivex_recode-function.patch |   33 ++++++++++++++++++++
 hivex.spec                                         |    7 +++-
 2 files changed, 38 insertions(+), 2 deletions(-)
---
diff --git a/0001-lib-Don-t-leak-errno-from-_hivex_recode-function.patch b/0001-lib-Don-t-leak-errno-from-_hivex_recode-function.patch
new file mode 100644
index 0000000..24ece49
--- /dev/null
+++ b/0001-lib-Don-t-leak-errno-from-_hivex_recode-function.patch
@@ -0,0 +1,33 @@
+From 4b3c3cd2b3d8d34601979feeb1390fddd442ab04 Mon Sep 17 00:00:00 2001
+From: "Richard W.M. Jones" <rjones at redhat.com>
+Date: Thu, 20 Nov 2014 21:37:19 +0000
+Subject: [PATCH] lib: Don't leak errno from _hivex_recode function.
+
+If iconv returns E2BIG, that's an internal indication for us, and not
+an error.  Don't leak the errno up to the user, as happened here:
+
+https://www.redhat.com/archives/libguestfs/2014-November/msg00140.html
+
+Thanks Nicolas Ecarnot.
+---
+ lib/utf16.c | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/lib/utf16.c b/lib/utf16.c
+index fe2c3bd..238f40a 100644
+--- a/lib/utf16.c
++++ b/lib/utf16.c
+@@ -58,6 +58,10 @@ _hivex_recode (const char *input_encoding, const char *input, size_t input_len,
+   if (r == (size_t) -1) {
+     if (errno == E2BIG) {
+       int err = errno;
++      /* Reset errno here because we don't want to accidentally
++       * return E2BIG to a library caller.
++       */
++      errno = 0;
+       size_t prev = outalloc;
+       /* Try again with a larger output buffer. */
+       free (out);
+-- 
+2.1.0
+
diff --git a/hivex.spec b/hivex.spec
index 9141e3d..81173bf 100644
--- a/hivex.spec
+++ b/hivex.spec
@@ -7,7 +7,7 @@
 
 Name:           hivex
 Version:        1.3.11
-Release:        3%{?dist}
+Release:        4%{?dist}
 Summary:        Read and write Windows Registry binary hive files
 
 License:        LGPLv2
@@ -23,6 +23,7 @@ BuildRequires:  autoconf, automake, libtool, gettext-devel
 Patch1:         0001-lib-write-fix-memory-leak.patch
 Patch2:         0002-lib-Increase-HIVEX_MAX_VALUE_LEN-to-8000000.patch
 Patch3:         0001-lib-Increase-HIVEX_MAX_SUBKEYS-to-25000.patch
+Patch4:         0001-lib-Don-t-leak-errno-from-_hivex_recode-function.patch
 
 BuildRequires:  perl
 BuildRequires:  perl-Test-Simple
@@ -166,6 +167,7 @@ autoreconf -i
 %patch1 -p1
 %patch2 -p1
 %patch3 -p1
+%patch4 -p1
 
 %build
 %configure
@@ -272,8 +274,9 @@ rm $RPM_BUILD_ROOT%{python_sitearch}/libhivexmod.la
 
 
 %changelog
-* Thu Nov 20 2014 Richard W.M. Jones <rjones at redhat.com> - 1.3.11-3
+* Thu Nov 20 2014 Richard W.M. Jones <rjones at redhat.com> - 1.3.11-4
 - Increase HIVEX_MAX_SUBKEYS.
+- Don't leak errno E2BIG to callers.
 
 * Fri Nov 14 2014 Richard W.M. Jones <rjones at redhat.com> - 1.3.11-2
 - Pull in a couple of upstream fixes:


More information about the scm-commits mailing list