From 671ea8cce47e9c556d283bd53b2c82b9c5ec2da4 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Wed, 7 Dec 2022 06:58:23 +0900
Subject: [PATCH] hexdecoct: add missing NULL check

Fixes oss-fuzz#54065 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54065).

Fixes #25650.

(cherry picked from commit 45655e776f3a4deaf68cc21a7716eba5181cbd49)
(cherry picked from commit 002fc46688e7d7057dbd7845defcc5bae758adde)

Conflict:code context adaptation
Reference:https://github.com/systemd/systemd-stable/commit/671ea8cce47e9c556d283bd53b2c82b9c5ec2da4
---
 src/basic/hexdecoct.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/basic/hexdecoct.c b/src/basic/hexdecoct.c
index 0922a49bb1..b9de5bfcda 100644
--- a/src/basic/hexdecoct.c
+++ b/src/basic/hexdecoct.c
@@ -606,7 +606,7 @@ ssize_t base64mem_full(
         if (!r)
                 return -ENOMEM;
 
-        for (x = p; x < (const uint8_t*) p + (l / 3) * 3; x += 3) {
+        for (x = p; x && x < (const uint8_t*) p + (l / 3) * 3; x += 3) {
                 /* x[0] == XXXXXXXX; x[1] == YYYYYYYY; x[2] == ZZZZZZZZ */
                 *(z++) = base64char(x[0] >> 2);                    /* 00XXXXXX */
                 *(z++) = base64char((x[0] & 3) << 4 | x[1] >> 4);  /* 00XXYYYY */
-- 
2.33.0

