* [PATCH cluster] fix #7326: corosync config: allow whitespace in values
@ 2026-09-29 13:31 Michal Fox
0 siblings, 0 replies; only message in thread
From: Michal Fox @ 2026-09-29 13:31 UTC (permalink / raw)
To: pve-devel
The corosync.conf parser split the whole file into whitespace separated
tokens and always took exactly one token as value. Values containing
whitespace, like a manually set cluster_name "my cluster", are accepted
by corosync, but made the parser fail with "missing ':' after key".
Any API call reading the corosync config then failed, for example when
adding an HA resource.
Parse the file line by line instead, like corosync does, and take the
rest of the line after the first ':' as value. Section headers and
closing brackets still need to be on their own line, which corosync
requires anyway.
Add a test config with whitespace in the cluster name.
Signed-off-by: Michal Fox <me@dualfroz.com>
---
src/PVE/Corosync.pm | 26 +++++++---------
.../cluster-name-with-spaces.conf | 30 +++++++++++++++++++
2 files changed, 41 insertions(+), 15 deletions(-)
create mode 100644 src/test/corosync_configs/cluster-name-with-spaces.conf
diff --git a/src/PVE/Corosync.pm b/src/PVE/Corosync.pm
index aef0d31..4be755a 100644
--- a/src/PVE/Corosync.pm
+++ b/src/PVE/Corosync.pm
@@ -99,23 +99,20 @@ sub parse_conf {
my $digest = Digest::SHA::sha1_hex(defined($raw) ? $raw : '');
$raw =~ s/#.*$//mg;
- $raw =~ s/\r?\n/ /g;
- $raw =~ s/\s+/ /g;
- $raw =~ s/^\s+//;
- $raw =~ s/\s*$//;
-
- my @tokens = split(/\s/, $raw);
my $conf = { 'main' => {} };
my $stack = [];
my $section = $conf->{main};
- while (defined(my $token = shift @tokens)) {
- my $nexttok = $tokens[0];
+ # like corosync itself, parse line by line, so that values may contain whitespace
+ for my $line (split(/\r?\n/, $raw)) {
+ $line =~ s/^\s+//;
+ $line =~ s/\s+$//;
+ next if $line eq '';
- if ($nexttok && ($nexttok eq '{')) {
- shift @tokens; # skip '{'
+ if ($line =~ m/^(\S+?)\s*\{$/) {
+ my $token = $1;
my $new_section = {};
if ($conf_array_sections->{$token}) {
$section->{$token} = [] if !defined($section->{$token});
@@ -130,17 +127,16 @@ sub parse_conf {
next;
}
- if ($token eq '}') {
+ if ($line eq '}') {
$section = pop @$stack;
die "parse error - uncexpected '}'\n" if !$section;
next;
}
- my $key = $token;
- die "missing ':' after key '$key'\n" if !($key =~ s/:$//);
+ my ($key, $value) = $line =~ m/^([^\s:]+)\s*:\s*(.*)$/
+ or die "parse error - unable to parse line '$line'\n";
- die "parse error - no value for '$key'\n" if !defined($nexttok);
- my $value = shift @tokens;
+ die "parse error - no value for '$key'\n" if $value eq '';
$section->{$key} = $value;
}
diff --git a/src/test/corosync_configs/cluster-name-with-spaces.conf b/src/test/corosync_configs/cluster-name-with-spaces.conf
new file mode 100644
index 0000000..e13b005
--- /dev/null
+++ b/src/test/corosync_configs/cluster-name-with-spaces.conf
@@ -0,0 +1,30 @@
+logging {
+ debug: off
+ to_syslog: yes
+}
+
+nodelist {
+ node {
+ name: prox1
+ nodeid: 1
+ quorum_votes: 1
+ ring0_addr: prox1
+ }
+}
+
+quorum {
+ provider: corosync_votequorum
+}
+
+totem {
+ cluster_name: cloud with spaces
+ config_version: 1
+ interface {
+ bindnetaddr: 192.168.0.42
+ ringnumber: 0
+ }
+ ip_version: ipv4
+ secauth: on
+ version: 2
+}
+
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-30 7:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-29 13:31 [PATCH cluster] fix #7326: corosync config: allow whitespace in values Michal Fox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox