mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2026-04-11 16:51:54 +02:00
89 lines
3.2 KiB
Diff
89 lines
3.2 KiB
Diff
From 33d5e8f7066116bd0a706c7cdda4950895164d34 Mon Sep 17 00:00:00 2001
|
|
From: Lars Ellenberg <lars.ellenberg@linbit.com>
|
|
Date: Wed, 9 Nov 2022 11:01:54 +0100
|
|
Subject: [PATCH] drbdadm: drop use of GLOB_MAGCHAR, use strchr heuristic only
|
|
|
|
Fixup for
|
|
2022-09-05 4a1b5900 drbdadm: allow files from an expanded include glob to vanish
|
|
|
|
When using the `include` statement, if the glob did not match any file,
|
|
there is nothing to do, silently ignore. Unless it was no glob, but a literal,
|
|
which we would expect to exist.
|
|
|
|
Also, there is a race between expanding a glob and accessing the file.
|
|
That also should not happen for literals, though.
|
|
|
|
Since we still had the heuristic anyways, because apparently |GLOB_MAGCHAR
|
|
does not happen for GLOB_NOMATCH returns, and there exist non-GNU libc that
|
|
don't (and likely won't) implement that extension, just forget about
|
|
(gl_flags & GLOB_MAGCHAR) but use the incomplete strchr heuristic only.
|
|
---
|
|
user/v9/drbdadm_parser.c | 35 ++++++++++++++++++++---------------
|
|
1 file changed, 20 insertions(+), 15 deletions(-)
|
|
|
|
diff --git a/user/v9/drbdadm_parser.c b/user/v9/drbdadm_parser.c
|
|
index 616ec0aa..4d9d7f99 100644
|
|
--- a/user/v9/drbdadm_parser.c
|
|
+++ b/user/v9/drbdadm_parser.c
|
|
@@ -1966,14 +1966,29 @@ void include_stmt(char *str)
|
|
size_t i;
|
|
int r;
|
|
|
|
- cwd = pushd_to_current_config_file_unless_stdin();
|
|
-
|
|
- /* """
|
|
+ /*
|
|
+ * If the glob did not match any file,
|
|
+ * there is nothing to do, silently ignore.
|
|
+ * Unless it was no glob, but a literal,
|
|
+ * which we would expect to exist.
|
|
+ *
|
|
+ * """
|
|
* As a GNU extension, pglob->gl_flags is set to the
|
|
* flags specified, ored with GLOB_MAGCHAR if any
|
|
* metacharacters were found.
|
|
* """
|
|
+ *
|
|
+ * But apparently |GLOB_MAGCHAR does not happen for GLOB_NOMATCH returns,
|
|
+ * at least not consistently :-(
|
|
+ * Also, there exist non-GNU libc
|
|
+ * So we have this incomplete strchr heuristic anyways.
|
|
*/
|
|
+ bool contains_glob_magic_char =
|
|
+ strchr(str, '*') ||
|
|
+ strchr(str, '?') ||
|
|
+ strchr(str, '[');
|
|
+
|
|
+ cwd = pushd_to_current_config_file_unless_stdin();
|
|
r = glob(str, 0, NULL, &glob_buf);
|
|
if (r == 0) {
|
|
for (i=0; i<glob_buf.gl_pathc; i++) {
|
|
@@ -1984,7 +1999,7 @@ void include_stmt(char *str)
|
|
if (f) {
|
|
include_file(f, strdup(glob_buf.gl_pathv[i]));
|
|
fclose(f);
|
|
- } else if (errno == ENOENT && glob_buf.gl_flags & GLOB_MAGCHAR) {
|
|
+ } else if (errno == ENOENT && contains_glob_magic_char) {
|
|
/* Noisily ignore race between glob expansion
|
|
* and actual open. */
|
|
err("%s:%d: include file vanished after glob expansion '%s'.\n",
|
|
@@ -1998,17 +2013,7 @@ void include_stmt(char *str)
|
|
}
|
|
globfree(&glob_buf);
|
|
} else if (r == GLOB_NOMATCH) {
|
|
- /*
|
|
- * If the glob did not match any file,
|
|
- * there is nothing to do, silently ignore.
|
|
- * Unless it was no glob, but a literal,
|
|
- * which we would expect to exist.
|
|
- * Apparently |GLOB_MAGCHAR does not happen for GLOB_NOMATCH returns,
|
|
- * at least not consistently :-(
|
|
- * So we have this strchr heuristic anyways.
|
|
- */
|
|
- /* if (!(glob_buf.gl_flags & GLOB_MAGCHAR)) { */
|
|
- if (!strchr(str, '?') && !strchr(str, '*') && !strchr(str, '[')) {
|
|
+ if (!contains_glob_magic_char) {
|
|
err("%s:%d: Failed to open include file '%s'.\n",
|
|
config_save, line, str);
|
|
config_valid = 0;
|