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