summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2019-12-18 07:48:57 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2019-12-18 07:48:57 +0000
commit7372212d96e3504861dc2af18a0ce8635d3263f6 (patch)
treefe3bb30dcdec59db3325013375d22276bd5e1572
parentbf5fc452d885208ced23221d9c1ea1df5310e213 (diff)
Do not rely on errno after glob(3) fails.
-rw-r--r--usr.bin/tmux/cmd-source-file.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/usr.bin/tmux/cmd-source-file.c b/usr.bin/tmux/cmd-source-file.c
index c22a82bfe34..1295668eee2 100644
--- a/usr.bin/tmux/cmd-source-file.c
+++ b/usr.bin/tmux/cmd-source-file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-source-file.c,v 1.42 2019/12/12 12:49:36 nicm Exp $ */
+/* $OpenBSD: cmd-source-file.c,v 1.43 2019/12/18 07:48:56 nicm Exp $ */
/*
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
@@ -130,7 +130,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
char *pattern, *cwd;
const char *path, *error;
glob_t g;
- int i;
+ int i, result;
u_int j;
cdata = xcalloc(1, sizeof *cdata);
@@ -158,9 +158,15 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
xasprintf(&pattern, "%s/%s", cwd, path);
log_debug("%s: %s", __func__, pattern);
- if (glob(pattern, 0, NULL, &g) != 0) {
- error = strerror(errno);
- if (errno != ENOENT || (~flags & CMD_PARSE_QUIET)) {
+ if ((result = glob(pattern, 0, NULL, &g)) != 0) {
+ if (result != GLOB_NOMATCH ||
+ (~flags & CMD_PARSE_QUIET)) {
+ if (result == GLOB_NOMATCH)
+ error = strerror(ENOENT);
+ else if (result == GLOB_NOSPACE)
+ error = strerror(ENOMEM);
+ else
+ error = strerror(EINVAL);
cmdq_error(item, "%s: %s", path, error);
retval = CMD_RETURN_ERROR;
}