From 6e017025aa74e56abcc908d74a50224a127026e3 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 22 Jan 2018 15:11:51 +0100 Subject: [PATCH] Fix bad string pointer arithmetic in condition reassert On `initctl reload` we reassert conditions, i.e. bring each still viable condition back in sync with the new reconf generation. This patch fixes an assumption in the reassert() callback that caused the following nasty transformation: /run/finit/cond/net/lo/up --> /run/finit/cond/lo/up The transformation was caused by the reassert() code assuming a /var/run prefix rather than /run. We must check the actual runpath, or like this patch does, use a path neutral way to find the base condition string. Signed-off-by: Joachim Nilsson --- src/cond-w.c | 8 +++++++- src/cond.h | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cond-w.c b/src/cond-w.c index 43be612c..2f035dc3 100644 --- a/src/cond-w.c +++ b/src/cond-w.c @@ -206,7 +206,13 @@ static int reassert(const char *fpath, const struct stat *sb, int tflg, struct F if (tflg != FTW_F) return 0; - nm = (char *)fpath + sizeof(COND_PATH); + nm = strstr((char *)fpath, COND_DIR); + if (!nm) { + _e("Incorrect condtion path %s, cannot reassert", fpath); + return 1; + } + + nm += sizeof(COND_DIR) + 1; _d("Reasserting %s => %s", fpath, nm); cond_set(nm); diff --git a/src/cond.h b/src/cond.h index a2a251c7..90378765 100644 --- a/src/cond.h +++ b/src/cond.h @@ -3,7 +3,8 @@ #include -#define COND_PATH _PATH_VARRUN "finit/cond" +#define COND_DIR "finit/cond" +#define COND_PATH _PATH_VARRUN COND_DIR #define COND_RECONF COND_PATH "/reconf" typedef enum cond_state {