summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Grajciar <jgrajcia@cisco.com>2018-07-25 10:49:42 +0200
committerDamjan Marion <dmarion@me.com>2018-07-25 19:58:45 +0000
commit605afa0cd959a1687aa4261215e9685d93b122f1 (patch)
treeae132e7fe3e66979319709f6e5476f65efce3cb3
parent4e6014fc9e8611eef16d9267151f1039ff00c190 (diff)
VPP-1332 memif: add/del socket filename bugfix
in case of relative path, create subdirs inside runtime dir. in case of absolute path, if folder does not exist return error. Change-Id: I01fe018102c69deb105160cfa18b741541d76c82 Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
-rw-r--r--src/plugins/memif/memif.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c
index a8bdeee62a5..0299e95ad60 100644
--- a/src/plugins/memif/memif.c
+++ b/src/plugins/memif/memif.c
@@ -620,6 +620,10 @@ memif_delete_socket_file (u32 sock_id)
int
memif_socket_filename_add_del (u8 is_add, u32 sock_id, u8 * sock_filename)
{
+ struct stat file_stat;
+ char *dir = 0;
+ u32 idx = 0;
+
if (sock_id == 0 || sock_id == ~0)
{
return VNET_API_ERROR_INVALID_ARGUMENT;
@@ -638,7 +642,17 @@ memif_socket_filename_add_del (u8 is_add, u32 sock_id, u8 * sock_filename)
if (sock_filename[0] != '/')
{
clib_error_t *error;
- error = vlib_unix_recursive_mkdir (vlib_unix_get_runtime_dir ());
+
+ /* copy runtime dir path */
+ vec_add (dir, vlib_unix_get_runtime_dir (),
+ strlen (vlib_unix_get_runtime_dir ()));
+
+ /* if sock_filename contains dirs, add them to path */
+ idx = strrchr ((char *) sock_filename, '/') - (char *) sock_filename;
+ vec_add (dir, sock_filename, idx);
+
+ /* create socket dir */
+ error = vlib_unix_recursive_mkdir (dir);
if (error)
{
clib_error_free (error);
@@ -651,7 +665,19 @@ memif_socket_filename_add_del (u8 is_add, u32 sock_id, u8 * sock_filename)
else
{
sock_filename = vec_dup (sock_filename);
+
+ /* check if directory exists */
+ idx = strrchr ((char *) sock_filename, '/') - (char *) sock_filename;
+ vec_add (dir, sock_filename, idx);
+
+ if (((stat (dir, &file_stat) == -1) || (!S_ISDIR (file_stat.st_mode)))
+ && (idx != 0))
+ {
+ vec_free (dir);
+ return VNET_API_ERROR_INVALID_ARGUMENT;
+ }
}
+ vec_free (dir);
return memif_add_socket_file (sock_id, sock_filename);
}