aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-05-09 16:17:55 +0200
committerdec05eba <dec05eba@protonmail.com>2024-05-09 16:17:55 +0200
commit49a4b976f52c6118ab5fb8a4aca052d52b31e238 (patch)
tree963c7570c7a1cb079969498a398ede7822d8a0b7 /src
parent774a5f49cecf8fc20452d0d9d7097b50754c6c0d (diff)
Proper strncpy null termination
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 16470b3..4e62fff 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -876,10 +876,19 @@ static bool try_card_has_valid_plane(const char *card_path) {
return false;
}
+static void string_copy(char *dst, const char *src, int len) {
+ int src_len = strlen(src);
+ int min_len = src_len;
+ if(len - 1 < min_len)
+ min_len = len - 1;
+ memcpy(dst, src, min_len);
+ dst[min_len] = '\0';
+}
+
/* output should be >= 128 bytes */
static bool gsr_get_valid_card_path(gsr_egl *egl, char *output) {
if(egl->dri_card_path) {
- strncpy(output, egl->dri_card_path, 127);
+ string_copy(output, egl->dri_card_path, 127);
return try_card_has_valid_plane(output);
}