diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-05-21 19:38:51 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2009-05-21 19:38:51 +0000 |
commit | a8ec5f1d09205f5a699031271150f978ab711848 (patch) | |
tree | 5856eed0e7e641878a93a041414b4b2e7e3be1a1 /cfg.c | |
parent | eb6007102e06fb70c251ade2fd34f50798ef6a13 (diff) |
stat(2) files before trying to load them to avoid problems, for example with "source-file /dev/zero".
This commit dedicated to Tom: protecting idiots from their own stupidity for more than 20 years.
Diffstat (limited to 'cfg.c')
-rw-r--r-- | cfg.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -1,4 +1,4 @@ -/* $Id: cfg.c,v 1.15 2009-03-31 22:23:43 nicm Exp $ */ +/* $Id: cfg.c,v 1.16 2009-05-21 19:38:51 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -17,6 +17,7 @@ */ #include <sys/types.h> +#include <sys/stat.h> #include <errno.h> #include <stdio.h> @@ -55,11 +56,21 @@ load_cfg(const char *path, char **cause) { FILE *f; u_int n; + struct stat sb; char *buf, *line, *ptr; size_t len; struct cmd_list *cmdlist; struct cmd_ctx ctx; + if (stat(path, &sb) != 0) { + xasprintf(cause, "%s: %s", path, strerror(errno)); + return (-1); + } + if (!S_ISREG(sb.st_mode)) { + xasprintf(cause, "%s: not a regular file", path); + return (-1); + } + if ((f = fopen(path, "rb")) == NULL) { xasprintf(cause, "%s: %s", path, strerror(errno)); return (1); |