33d974
From 1d90ea86a0ac6c5863597880b33a18755aff819c Mon Sep 17 00:00:00 2001
40f388
From: "Richard W.M. Jones" <rjones@redhat.com>
40f388
Date: Thu, 20 Nov 2014 21:37:19 +0000
214838
Subject: [PATCH 04/16] lib: Don't leak errno from _hivex_recode function.
40f388
40f388
If iconv returns E2BIG, that's an internal indication for us, and not
40f388
an error.  Don't leak the errno up to the user, as happened here:
40f388
40f388
https://www.redhat.com/archives/libguestfs/2014-November/msg00140.html
40f388
40f388
Thanks Nicolas Ecarnot.
33d974
33d974
(cherry picked from commit 4b3c3cd2b3d8d34601979feeb1390fddd442ab04)
40f388
---
40f388
 lib/utf16.c | 4 ++++
40f388
 1 file changed, 4 insertions(+)
40f388
40f388
diff --git a/lib/utf16.c b/lib/utf16.c
33d974
index f4299f2..3b54b01 100644
40f388
--- a/lib/utf16.c
40f388
+++ b/lib/utf16.c
33d974
@@ -59,6 +59,10 @@ _hivex_recode (const char *input_encoding, const char *input, size_t input_len,
40f388
   if (r == (size_t) -1) {
40f388
     if (errno == E2BIG) {
40f388
       int err = errno;
40f388
+      /* Reset errno here because we don't want to accidentally
40f388
+       * return E2BIG to a library caller.
40f388
+       */
40f388
+      errno = 0;
40f388
       size_t prev = outalloc;
40f388
       /* Try again with a larger output buffer. */
40f388
       free (out);
40f388
-- 
33d974
1.8.3.1
40f388