iconv: Fix possible null-pointer dereference.

Message ID 20220331125546.342772-1-d.chestnyh@omp.ru
State New
Headers
Series iconv: Fix possible null-pointer dereference. |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Dmitry Chestnyh March 31, 2022, 12:55 p.m. UTC
  The dereference can appear at iconv.c:54.
This problem was found by SVACE static analyzer.
---
 iconv/iconv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Andreas Schwab March 31, 2022, 1:24 p.m. UTC | #1
On Mär 31 2022, Dmitry Chestnyh wrote:

> The dereference can appear at iconv.c:54.

When inbuf isn't NULL then outbuf cannot be NULL.
  

Patch

diff --git a/iconv/iconv.c b/iconv/iconv.c
index e805c4c59d..1c3c517ad3 100644
--- a/iconv/iconv.c
+++ b/iconv/iconv.c
@@ -35,7 +35,7 @@  iconv (iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf,
   size_t irreversible;
   int result;
 
-  if (__glibc_unlikely (inbuf == NULL || *inbuf == NULL))
+  if (__glibc_unlikely (inbuf == NULL || *inbuf == NULL || outbuf == NULL))
     {
       if (outbuf == NULL || *outbuf == NULL)
 	result = __gconv (gcd, NULL, NULL, NULL, NULL, &irreversible);