From 93f8a19b6f9884f382d24f7650822d99cbb26c6d Mon Sep 17 00:00:00 2001
From: NAM UK KIM <namuk2004@naver.com>
Date: Mon, 6 May 2024 16:09:01 +0900
Subject: [PATCH] Change strlcat function name from redis to valkey (#440)

Updated strlcat function and macros name (redis_strlcat ->
valkey_strlcat).

I think the standard strcat function is not safe.
(https://codeql.github.com/codeql-query-help/cpp/cpp-unsafe-strcat/)
So, it would be better to keep it as a safe function.

Signed-off-by: NAM UK KIM <namuk2004@naver.com>
---
 src/fmacros.h | 2 +-
 src/rdb.c     | 4 ++--
 src/strl.c    | 2 +-
 src/util.h    | 2 +-
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/fmacros.h b/src/fmacros.h
index e629d1be2..aceda1c28 100644
--- a/src/fmacros.h
+++ b/src/fmacros.h
@@ -65,7 +65,7 @@
 #if (__GNUC__ && __GNUC__ >= 4) && !defined __APPLE__
 int sprintf(char *str, const char *format, ...) __attribute__((deprecated("please avoid use of unsafe C functions. prefer use of snprintf instead")));
 char *strcpy(char *restrict dest, const char *src) __attribute__((deprecated("please avoid use of unsafe C functions. prefer use of valkey_strlcpy instead")));
-char *strcat(char *restrict dest, const char *restrict src) __attribute__((deprecated("please avoid use of unsafe C functions. prefer use of redis_strlcat instead")));
+char *strcat(char *restrict dest, const char *restrict src) __attribute__((deprecated("please avoid use of unsafe C functions. prefer use of valkey_strlcat instead")));
 #endif
 
 #ifdef __linux__
diff --git a/src/rdb.c b/src/rdb.c
index 0bf451324..206cca690 100644
--- a/src/rdb.c
+++ b/src/rdb.c
@@ -1615,8 +1615,8 @@ void rdbRemoveTempFile(pid_t childpid, int from_signal) {
     /* Generate temp rdb file name using async-signal safe functions. */
     ll2string(pid, sizeof(pid), childpid);
     valkey_strlcpy(tmpfile, "temp-", sizeof(tmpfile));
-    redis_strlcat(tmpfile, pid, sizeof(tmpfile));
-    redis_strlcat(tmpfile, ".rdb", sizeof(tmpfile));
+    valkey_strlcat(tmpfile, pid, sizeof(tmpfile));
+    valkey_strlcat(tmpfile, ".rdb", sizeof(tmpfile));
 
     if (from_signal) {
         /* bg_unlink is not async-signal-safe, but in this case we don't really
diff --git a/src/strl.c b/src/strl.c
index e36faaab6..0453e0608 100644
--- a/src/strl.c
+++ b/src/strl.c
@@ -53,7 +53,7 @@ valkey_strlcpy(char *dst, const char *src, size_t dsize)
  * If retval >= dsize, truncation occurred.
  */
 size_t
-redis_strlcat(char *dst, const char *src, size_t dsize)
+valkey_strlcat(char *dst, const char *src, size_t dsize)
 {
     const char *odst = dst;
     const char *osrc = src;
diff --git a/src/util.h b/src/util.h
index 79fe743f4..ee50e2901 100644
--- a/src/util.h
+++ b/src/util.h
@@ -98,7 +98,7 @@ int snprintf_async_signal_safe(char *to, size_t n, const char *fmt, ...)
 int snprintf_async_signal_safe(char *to, size_t n, const char *fmt, ...);
 #endif
 size_t valkey_strlcpy(char *dst, const char *src, size_t dsize);
-size_t redis_strlcat(char *dst, const char *src, size_t dsize);
+size_t valkey_strlcat(char *dst, const char *src, size_t dsize);
 
 #ifdef SERVER_TEST
 int utilTest(int argc, char **argv, int flags);