diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2021-02-19 18:09:17 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-02-19 18:09:17 +0000 |
commit | 6fe4daaa16730017304824cc2193bb610ea33afd (patch) | |
tree | fe4363ed676a1331bd76d91a9bc9e8ac37d92679 | |
parent | 18dd0731f6126aa0fa5ddc5c556129c3698ef366 (diff) | |
parent | 20c023fdb26fabdec1d49e36eefd62efe9c6ef8b (diff) | |
download | bionic-6fe4daaa16730017304824cc2193bb610ea33afd.tar.gz |
Merge "iconv(3): ignore src_bytes_left if src_bytes is null."
-rw-r--r-- | libc/bionic/iconv.cpp | 4 | ||||
-rw-r--r-- | tests/iconv_test.cpp | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/libc/bionic/iconv.cpp b/libc/bionic/iconv.cpp index 015d70f5e..79a429cb9 100644 --- a/libc/bionic/iconv.cpp +++ b/libc/bionic/iconv.cpp @@ -356,6 +356,10 @@ size_t iconv(iconv_t __converter, errno = EBADF; return -1; } + + // Since none of our encodings are stateful, state flushing is a no-op. + if (!__src_buf) return 0; + return __converter->Convert(__src_buf, __src_bytes_left, __dst_buf, __dst_bytes_left); } diff --git a/tests/iconv_test.cpp b/tests/iconv_test.cpp index 768b4fddd..bd9900039 100644 --- a/tests/iconv_test.cpp +++ b/tests/iconv_test.cpp @@ -451,5 +451,13 @@ TEST(iconv, iconv_initial_shift_state) { EXPECT_EQ(0, errno); EXPECT_EQ(sizeof(out_buf), out_bytes); + // Is a null pointer and so is in_bytes. This isn't specified by POSIX, but + // glibc and macOS both allow that, where Android historically didn't. + // https://issuetracker.google.com/180598400 + errno = 0; + ASSERT_EQ(static_cast<size_t>(0), iconv(c, nullptr, nullptr, &out, &out_bytes)); + EXPECT_EQ(0, errno); + EXPECT_EQ(sizeof(out_buf), out_bytes); + EXPECT_EQ(0, iconv_close(c)); } |