From 50dae247795c9390bac885b1b222b06efb29f797 Mon Sep 17 00:00:00 2001 From: gparemsky Date: Wed, 30 Jul 2025 08:24:48 -0400 Subject: [PATCH] Fix config parser to handle inline comments The config parser now properly handles inline comments in configuration directives. Previously, 'bind * -::* # comment' would fail because the parser treated # and subsequent text as additional arguments. This fix strips inline comments before parsing, while preserving any # characters that appear inside quoted strings. Fixes the issue where Redis fails to start with: Warning: Could not create server TCP listening socket #:6379 --- src/config.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/config.c b/src/config.c index 4c30fd953d..ddbab4b84a 100644 --- a/src/config.c +++ b/src/config.c @@ -454,6 +454,25 @@ void loadServerConfigFromString(char *config) { /* Skip comments and blank lines */ if (lines[i][0] == '#' || lines[i][0] == '\0') continue; + /* Strip inline comments */ + char *comment = strchr(lines[i], '#'); + if (comment) { + /* Check if # is inside quotes by counting quotes before it */ + char *p = lines[i]; + int in_quotes = 0; + while (p < comment) { + if (*p == '"' || *p == '\''){ + in_quotes = !in_quotes; + } + p++; + } + /* Only treat as comment if not inside quotes */ + if (!in_quotes){ + *comment = '\0'; + lines[i] = sdstrim(lines[i], " \t\r\n"); + } + } + /* Split into arguments */ argv = sdssplitargs(lines[i],&argc); if (argv == NULL) {