public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Michal Fox <me@dualfroz.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH cluster] fix #7326: corosync config: allow whitespace in values
Date: Tue, 29 Sep 2026 15:31:27 +0200	[thread overview]
Message-ID: <20260929133127.2500284-1-me@dualfroz.com> (raw)

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




                 reply	other threads:[~2026-09-30  7:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260929133127.2500284-1-me@dualfroz.com \
    --to=me@dualfroz.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal