diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-05-17 18:49:16 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-05-17 18:49:16 +0200 |
commit | 6cff1a49d2b124266f8da41065c471d80cdd32e2 (patch) | |
tree | ff15da38af695c0bb149165db201765e0f4fc050 /kms | |
parent | 715a3c612a606465ee5526efe53029741ee4c7f9 (diff) |
Fix all warnings
Diffstat (limited to 'kms')
-rw-r--r-- | kms/client/kms_client.c | 11 | ||||
-rw-r--r-- | kms/server/kms_server.c | 11 | ||||
-rw-r--r-- | kms/server/project.conf | 3 |
3 files changed, 23 insertions, 2 deletions
diff --git a/kms/client/kms_client.c b/kms/client/kms_client.c index bdc556b..587dda3 100644 --- a/kms/client/kms_client.c +++ b/kms/client/kms_client.c @@ -96,6 +96,15 @@ static bool create_socket_path(char *output_path, size_t output_path_size) { return true; } +static void strncpy_safe(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'; +} + int gsr_kms_client_init(gsr_kms_client *self, const char *card_path) { self->kms_server_pid = -1; self->socket_fd = -1; @@ -152,7 +161,7 @@ int gsr_kms_client_init(gsr_kms_client *self, const char *card_path) { } local_addr.sun_family = AF_UNIX; - strncpy(local_addr.sun_path, self->socket_path, sizeof(local_addr.sun_path)); + strncpy_safe(local_addr.sun_path, self->socket_path, sizeof(local_addr.sun_path)); if(bind(self->socket_fd, (struct sockaddr*)&local_addr, sizeof(local_addr.sun_family) + strlen(local_addr.sun_path)) == -1) { fprintf(stderr, "gsr error: gsr_kms_client_init: failed to bind socket, error: %s\n", strerror(errno)); goto err; diff --git a/kms/server/kms_server.c b/kms/server/kms_server.c index 9f381f6..5aa6590 100644 --- a/kms/server/kms_server.c +++ b/kms/server/kms_server.c @@ -294,6 +294,15 @@ static double clock_get_monotonic_seconds(void) { return (double)ts.tv_sec + (double)ts.tv_nsec * 0.000000001; } +static void strncpy_safe(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'; +} + int main(int argc, char **argv) { if(argc != 3) { fprintf(stderr, "usage: kms_server <domain_socket_path> <card_path>\n"); @@ -329,7 +338,7 @@ int main(int argc, char **argv) { while(clock_get_monotonic_seconds() - start_time < connect_timeout_sec) { struct sockaddr_un remote_addr = {0}; remote_addr.sun_family = AF_UNIX; - strncpy(remote_addr.sun_path, domain_socket_path, sizeof(remote_addr.sun_path)); + strncpy_safe(remote_addr.sun_path, domain_socket_path, sizeof(remote_addr.sun_path)); // TODO: Check if parent disconnected if(connect(socket_fd, (struct sockaddr*)&remote_addr, sizeof(remote_addr.sun_family) + strlen(remote_addr.sun_path)) == -1) { if(errno == ECONNREFUSED || errno == ENOENT) { diff --git a/kms/server/project.conf b/kms/server/project.conf index cf863c1..26a1947 100644 --- a/kms/server/project.conf +++ b/kms/server/project.conf @@ -4,5 +4,8 @@ type = "executable" version = "1.0.0" platforms = ["posix"] +[config] +error_on_warning = "true" + [dependencies] libdrm = ">=2" |