From 57084e54082a29d19d2e4b71581c2a4980f8ce15 Mon Sep 17 00:00:00 2001 From: Jakub Grajciar Date: Mon, 1 Mar 2021 08:45:17 +0100 Subject: libmemif: socket filename length 108 Dynamic size array was causing trouble in strlcpy. LINUX allows for max 108 filename length, so we can use that to make the array constant size. Type: fix Signed-off-by: Jakub Grajciar Change-Id: I76b1fc41f9d93cfbc9ad11bdca0c96a1fc261e84 --- extras/libmemif/src/main.c | 28 ++-------------------------- extras/libmemif/src/memif_private.h | 2 +- 2 files changed, 3 insertions(+), 27 deletions(-) (limited to 'extras/libmemif/src') diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c index 1eb6929137e..36f1251a158 100644 --- a/extras/libmemif/src/main.c +++ b/extras/libmemif/src/main.c @@ -948,13 +948,7 @@ memif_create_socket (memif_socket_handle_t * sock, const char *filename, } memset (ms, 0, sizeof (memif_socket_t)); /* set filename */ - ms->filename = lm->alloc (strlen (filename) + sizeof (char)); - if (ms->filename == NULL) - { - err = MEMIF_ERR_NOMEM; - goto error; - } - memset (ms->filename, 0, strlen (filename) + sizeof (char)); + memset (ms->filename, 0, sizeof (ms->filename)); strlcpy ((char *) ms->filename, filename, sizeof (ms->filename)); ms->type = MEMIF_SOCKET_TYPE_NONE; @@ -977,11 +971,6 @@ memif_create_socket (memif_socket_handle_t * sock, const char *filename, error: if (ms != NULL) { - if (ms->filename != NULL) - { - lm->free (ms->filename); - ms->filename = NULL; - } if (ms->fd > 0) { close (ms->fd); @@ -1032,13 +1021,7 @@ memif_per_thread_create_socket (memif_per_thread_main_handle_t pt_main, memset (ms, 0, sizeof (memif_socket_t)); ms->lm = lm; /* set filename */ - ms->filename = lm->alloc (strlen (filename) + sizeof (char)); - if (ms->filename == NULL) - { - err = MEMIF_ERR_NOMEM; - goto error; - } - memset (ms->filename, 0, strlen (filename) + sizeof (char)); + memset (ms->filename, 0, sizeof (ms->filename)); strlcpy ((char *) ms->filename, filename, sizeof (ms->filename)); ms->type = MEMIF_SOCKET_TYPE_NONE; @@ -1061,11 +1044,6 @@ memif_per_thread_create_socket (memif_per_thread_main_handle_t pt_main, error: if (ms != NULL) { - if (ms->filename != NULL) - { - lm->free (ms->filename); - ms->filename = NULL; - } if (ms->fd > 0) { close (ms->fd); @@ -1796,8 +1774,6 @@ memif_delete_socket (memif_socket_handle_t * sock) lm->free (ms->interface_list); ms->interface_list = NULL; - lm->free (ms->filename); - ms->filename = NULL; lm->free (ms); *sock = ms = NULL; diff --git a/extras/libmemif/src/memif_private.h b/extras/libmemif/src/memif_private.h index 59899fd6285..9542936983e 100644 --- a/extras/libmemif/src/memif_private.h +++ b/extras/libmemif/src/memif_private.h @@ -193,7 +193,7 @@ typedef struct int fd; uint16_t use_count; memif_socket_type_t type; - uint8_t *filename; + uint8_t filename[108]; /* unique database */ struct libmemif_main *lm; uint16_t interface_list_len; -- cgit 1.2.3-korg