text.c: use strncpy instead of strcpy for better security
authorduna.oh <duna.oh@samsung.com>
Tue, 18 Jul 2023 13:02:05 +0000 (22:02 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Thu, 21 Dec 2023 23:47:25 +0000 (08:47 +0900)
Change-Id: Idf6357ae19655f5de30017ad575fdc6b3193cd96

src/text.c

index 290a5ae..3c8ffd3 100644 (file)
@@ -286,13 +286,13 @@ ModMaskText(struct xkb_context *ctx, const struct xkb_mod_set *mods,
             pos += ret;
     }
 
-    return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);
+    return strncpy(xkb_context_get_buffer(ctx, pos + 1), buf, pos + 1);
 }
 
 const char *
 LedStateMaskText(struct xkb_context *ctx, enum xkb_state_component mask)
 {
-    char buf[1024];
+    char buf[1024] = {0};
     size_t pos = 0;
 
     if (mask == 0)
@@ -315,13 +315,13 @@ LedStateMaskText(struct xkb_context *ctx, enum xkb_state_component mask)
             pos += ret;
     }
 
-    return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);
+    return strncpy(xkb_context_get_buffer(ctx, pos + 1), buf, pos + 1);
 }
 
 const char *
 ControlMaskText(struct xkb_context *ctx, enum xkb_action_controls mask)
 {
-    char buf[1024];
+    char buf[1024] = {0};
     size_t pos = 0;
 
     if (mask == 0)
@@ -347,5 +347,5 @@ ControlMaskText(struct xkb_context *ctx, enum xkb_action_controls mask)
             pos += ret;
     }
 
-    return strcpy(xkb_context_get_buffer(ctx, pos + 1), buf);
+    return strncpy(xkb_context_get_buffer(ctx, pos + 1), buf, pos + 1);
 }