opendoas

my fork of doas with custom prompt
git clone git://git.kocotian.pl/opendoas.git
Log | Files | Refs | README | LICENSE

commit f94cf30ade3dcd20e74ffa347359e9bf78428e6e
parent 6d8f0e61e0449a0446ef820521e94f5093b1da41
Author: deraadt <deraadt>
Date:   Wed,  3 Jul 2019 03:24:02 +0000

snprintf/vsnprintf return < 0 on error, rather than -1.

Diffstat:
Mdoas.c | 40++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+), 0 deletions(-)

diff --git a/doas.c b/doas.c @@ -249,6 +249,46 @@ good: } #endif +#ifdef __OpenBSD__ +int +unveilcommands(const char *ipath, const char *cmd) +{ + char *path = NULL, *p; + int unveils = 0; + + if (strchr(cmd, '/') != NULL) { + if (unveil(cmd, "x") != -1) + unveils++; + goto done; + } + + if (!ipath) { + errno = ENOENT; + goto done; + } + path = strdup(ipath); + if (!path) { + errno = ENOENT; + goto done; + } + for (p = path; p && *p; ) { + char buf[PATH_MAX]; + char *cp = strsep(&p, ":"); + + if (cp) { + int r = snprintf(buf, sizeof buf, "%s/%s", cp, cmd); + if (r >= 0 && r < sizeof buf) { + if (unveil(buf, "x") != -1) + unveils++; + } + } + } +done: + free(path); + return (unveils); +} +#endif + int main(int argc, char **argv) {