From 2ee140ec27335ca50e813080ee0e85e4ab86af37 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sat, 11 Feb 2017 17:04:27 +0100 Subject: ipcpd: Prevent access to directory before init Doing a directory query before the IPCP is has bootstrapped or is enrolled will result in an assertion failure as the directory is not yet ready. This fixes flow allocation over the LLC shim (which triggers a directory query from the IRMd) with a normal IPCP present. --- src/ipcpd/normal/dir.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ipcpd/normal/dir.c b/src/ipcpd/normal/dir.c index d30b9ec0..703f4e79 100644 --- a/src/ipcpd/normal/dir.c +++ b/src/ipcpd/normal/dir.c @@ -31,21 +31,22 @@ #include #include +#define DIR_PATH "/" DIR_NAME + static char dir_path[RIB_MAX_PATH_LEN + 1]; static void dir_path_reset(void) { - dir_path[strlen("/" DIR_NAME)]= '\0'; - assert(strcmp("/" DIR_NAME, dir_path) == 0); + dir_path[strlen(DIR_PATH)]= '\0'; + assert(strcmp(DIR_PATH, dir_path) == 0); } int dir_init(void) { /*FIXME: set ribmgr dissemination here */ - if (rib_add(RIB_ROOT, DIR_NAME)) return -1; - strcpy(dir_path, "/" DIR_NAME); + strcpy(dir_path, DIR_PATH); return 0; } @@ -66,6 +67,9 @@ int dir_name_reg(char * name) assert(name); + if (ipcp_get_state() != IPCP_OPERATIONAL) + return -EPERM; + dir_path_reset(); ret = rib_add(dir_path, name); @@ -91,6 +95,9 @@ int dir_name_unreg(char * name) assert(name); + if (ipcp_get_state() != IPCP_OPERATIONAL) + return -EPERM; + dir_path_reset(); rib_path_append(dir_path, name); @@ -116,6 +123,9 @@ int dir_name_query(char * name) { size_t len; + if (ipcp_get_state() != IPCP_OPERATIONAL) + return -EPERM; + dir_path_reset(); rib_path_append(dir_path, name); -- cgit v1.2.3