diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-12-11 19:14:43 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-12-11 19:14:43 +0000 |
commit | 7860fc92d35bf2e4adc56128457ab8164b440855 (patch) | |
tree | 073d91d01f1033cf6ef5136e9a33631d7fd2e574 | |
parent | 1a7a0c79040d9efa654c151d8a057f34eb9be585 (diff) | |
download | s6-7860fc92d35bf2e4adc56128457ab8164b440855.tar.xz |
Bugfix: s6-fdholderd crash when regex defs not present
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | src/fdholder/s6-fdholderd.c | 34 |
2 files changed, 20 insertions, 15 deletions
@@ -11,6 +11,7 @@ /s6-ftrig-notify /s6-ftrig-wait /s6lockd +/s6lockd-helper /s6-cleanfifodir /s6-mkfifodir /s6-svscan diff --git a/src/fdholder/s6-fdholderd.c b/src/fdholder/s6-fdholderd.c index 10c3600..2b96553 100644 --- a/src/fdholder/s6-fdholderd.c +++ b/src/fdholder/s6-fdholderd.c @@ -544,46 +544,47 @@ static int makere (regex_t *re, char const *s, char const *var) static void defaultre (regex_t *re) { - int r = regcomp(re, "^$", REG_EXTENDED | REG_NOSUB) ; + int r = regcomp(re, ".^", REG_EXTENDED | REG_NOSUB) ; if (r) { char buf[256] ; regerror(r, re, buf, 256) ; - strerr_diefu2x(100, "compile ^$ into a regular expression: ", buf) ; + strerr_diefu2x(100, "compile .^ into a regular expression: ", buf) ; } } -static inline int parse_env (char const *const *envp, regex_t *rre, regex_t *wre, unsigned int *flags) +static inline int parse_env (char const *const *envp, regex_t *rre, regex_t *wre, unsigned int *flags, unsigned int *donep) { + unsigned int done = 0 ; unsigned int fl = 0 ; - int rre_done = 0, wre_done = 0 ; for (; *envp ; envp++) { if (str_start(*envp, "S6_FDHOLDER_GETDUMP=")) fl |= 1 ; if (str_start(*envp, "S6_FDHOLDER_SETDUMP=")) fl |= 2 ; if (str_start(*envp, "S6_FDHOLDER_LIST=")) fl |= 4 ; - if (!rre_done) + if (!(done & 1)) { - rre_done = makere(rre, *envp, "S6_FDHOLDER_RETRIEVE_REGEX") ; - if (rre_done < 0) + int r = makere(rre, *envp, "S6_FDHOLDER_RETRIEVE_REGEX") ; + if (r < 0) { - if (wre_done) regfree(wre) ; + if (done & 2) regfree(wre) ; return 0 ; } + else if (r) done |= 1 ; } - if (!wre_done) + if (!(done & 2)) { - wre_done = makere(wre, *envp, "S6_FDHOLDER_STORE_REGEX") ; - if (wre_done < 0) + int r = makere(wre, *envp, "S6_FDHOLDER_STORE_REGEX") ; + if (r < 0) { - if (rre_done) regfree(rre) ; + if (done & 1) regfree(rre) ; return 0 ; } + else if (r) done |= 2 ; } } - if (!rre_done) defaultre(rre) ; - if (!wre_done) defaultre(wre) ; *flags = fl ; + *donep = done ; return 1 ; } @@ -593,6 +594,7 @@ static inline int new_connection (int fd, regex_t *rre, regex_t *wre, unsigned i s6_accessrules_result_t result = S6_ACCESSRULES_ERROR ; uid_t uid ; gid_t gid ; + unsigned int done = 0 ; if (getpeereid(fd, &uid, &gid) < 0) { @@ -633,7 +635,7 @@ static inline int new_connection (int fd, regex_t *rre, regex_t *wre, unsigned i return 0 ; } envp[n] = 0 ; - if (!parse_env(envp, rre, wre, flags)) + if (!parse_env(envp, rre, wre, flags, &done)) { if (verbosity) strerr_warnwu1sys("parse_env") ; s6_accessrules_params_free(¶ms) ; @@ -641,6 +643,8 @@ static inline int new_connection (int fd, regex_t *rre, regex_t *wre, unsigned i } s6_accessrules_params_free(¶ms) ; } + if (!(done & 1)) defaultre(rre) ; + if (!(done & 2)) defaultre(wre) ; return 1 ; } |