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 <jgrajcia@cisco.com>
Change-Id: I76b1fc41f9d93cfbc9ad11bdca0c96a1fc261e84
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c
index 1eb6929..36f1251 100644
--- a/extras/libmemif/src/main.c
+++ b/extras/libmemif/src/main.c
@@ -948,13 +948,7 @@
}
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 @@
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 @@
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 @@
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 @@
lm->free (ms->interface_list);
ms->interface_list = NULL;
- lm->free (ms->filename);
- ms->filename = NULL;
lm->free (ms);
*sock = ms = NULL;