summaryrefslogtreecommitdiff
path: root/lib/util/charset/iconv.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/util/charset/iconv.c')
-rw-r--r--lib/util/charset/iconv.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/util/charset/iconv.c b/lib/util/charset/iconv.c
index 045fd1329b..16ce92ea82 100644
--- a/lib/util/charset/iconv.c
+++ b/lib/util/charset/iconv.c
@@ -193,14 +193,15 @@ _PUBLIC_ size_t smb_iconv(smb_iconv_t cd,
while (*inbytesleft > 0) {
char *bufp1 = cvtbuf;
const char *bufp2 = cvtbuf;
-
+ int saved_errno = errno;
+ bool pull_failed = false;
bufsize = SMB_ICONV_BUFSIZE;
if (cd->pull(cd->cd_pull,
inbuf, inbytesleft, &bufp1, &bufsize) == -1
&& errno != E2BIG) {
- talloc_free(cvtbuf);
- return -1;
+ saved_errno = errno;
+ pull_failed = true;
}
bufsize = SMB_ICONV_BUFSIZE - bufsize;
@@ -210,6 +211,10 @@ _PUBLIC_ size_t smb_iconv(smb_iconv_t cd,
outbuf, outbytesleft) == -1) {
talloc_free(cvtbuf);
return -1;
+ } else if (pull_failed) {
+ /* We want the pull errno if possible */
+ errno = saved_errno;
+ return -1;
}
}
talloc_free(cvtbuf);