From 605afa0cd959a1687aa4261215e9685d93b122f1 Mon Sep 17 00:00:00 2001 From: Jakub Grajciar Date: Wed, 25 Jul 2018 10:49:42 +0200 Subject: 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 --- src/plugins/memif/memif.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/plugins') 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); } -- cgit 1.2.3-korg