diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-05-09 16:17:38 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-05-09 16:17:38 +0200 |
commit | f1eb8934930d0bb5e4f64ce24ca9971f0655c04f (patch) | |
tree | d1f21120dcca846d21b2a3031bee22f174693c56 /src/utils.c | |
parent | 447b5d0f0ba9ea34b90acd8d6e23005f15f1c242 (diff) |
Proper strncpy null termination
Diffstat (limited to 'src/utils.c')
-rw-r--r-- | src/utils.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/utils.c b/src/utils.c index 7dd1890..40d652e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -414,9 +414,18 @@ 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'; +} + 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); } @@ -435,7 +444,7 @@ bool gsr_card_path_get_render_path(const char *card_path, char *render_path) { char *render_path_tmp = drmGetRenderDeviceNameFromFd(fd); if(render_path_tmp) { - strncpy(render_path, render_path_tmp, 127); + string_copy(render_path, render_path_tmp, 127); free(render_path_tmp); close(fd); return true; |