From 1589cc1d6597c278ceb475d175cbe2fcff59ad5b Mon Sep 17 00:00:00 2001 From: "duna.oh" Date: Tue, 18 Jul 2023 22:02:05 +0900 Subject: [PATCH] text.c: use strncpy instead of strcpy for better security Change-Id: Idf6357ae19655f5de30017ad575fdc6b3193cd96 --- src/text.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/text.c b/src/text.c index 60edb03..e85b0eb 100644 --- a/src/text.c +++ b/src/text.c @@ -283,13 +283,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) @@ -312,13 +312,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) @@ -344,5 +344,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); } -- 2.7.4