Blob Blame History Raw
From 1d90ea86a0ac6c5863597880b33a18755aff819c Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 20 Nov 2014 21:37:19 +0000
Subject: [PATCH 04/12] 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.

(cherry picked from commit 4b3c3cd2b3d8d34601979feeb1390fddd442ab04)
---
 lib/utf16.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/utf16.c b/lib/utf16.c
index f4299f2..3b54b01 100644
--- a/lib/utf16.c
+++ b/lib/utf16.c
@@ -59,6 +59,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);
-- 
1.8.3.1