From 9db4ba5519938c710c63b66f4a9ba2fc9311dde7 Mon Sep 17 00:00:00 2001
From: obarun <eric@obarun.org>
Date: Tue, 28 Sep 2021 21:51:22 +1100
Subject: [PATCH] end the string with 0 before copying it

---
 src/lib66/ss_resolve.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/lib66/ss_resolve.c b/src/lib66/ss_resolve.c
index df94c486..9f4130e0 100644
--- a/src/lib66/ss_resolve.c
+++ b/src/lib66/ss_resolve.c
@@ -1658,15 +1658,17 @@ int ss_resolve_find_cdb(stralloc *result, cdb const *c,char const *key)
     if (!r)
         log_warnusys_return(LOG_EXIT_ZERO,"unknown cdb key: ",key) ;
 
-    if (!cdata.len)
-        log_warnusys_return(LOG_EXIT_ZERO,"empty value of cdb key: ",key) ;
+    char pack[cdata.len + 1] ;
+    memcpy(pack,cdata.s, cdata.len) ;
+    pack[cdata.len] = 0 ;
 
-    if (!auto_stra(result,cdata.s))
-        log_warnusys_return(LOG_EXIT_LESSONE,"stralloc") ;
+    uint32_unpack_big(pack, &x) ;
 
-    uint32_unpack_big(cdata.s, &x) ;
+    if (!auto_stra(result,pack))
+        log_warnusys_return(LOG_EXIT_LESSONE,"stralloc") ;
 
     return x ;
+
 }
 
 int ss_resolve_read_cdb(ss_resolve_t *dres, char const *name)
-- 
GitLab