Skip to content

Bug: manage_boot_params.sh fails to parse syslinux.cfg with Windows line endings (CRLF) #2523

@mgutt

Description

@mgutt

Problem

The manage_boot_params.sh script fails to correctly parse /boot/syslinux/syslinux.cfg when the file contains Windows-style (CRLF, \r\n).

Reproduction

Run the script:

OPERATION=read_config /usr/local/emhttp/plugins/dynamix/scripts/manage_boot_params.sh

returns broken JSON:

{
  "nvme_disable": "0",
  "acs_override": "",
  "vfio_unsafe": "0",
  "efifb_off": "0",
  "vesafb_off": "0",
  "simplefb_off": "0",
  "sysfb_blacklist": "0",
  "acpi_lax": "0",
  "ghes_disable": "0",
  "usb_autosuspend": "0",
  "pcie_aspm_off": "0",
  "pcie_port_pm_off": "0",
  "pci_noaer": "0",
  "pci_realloc": "0",
  "custom_params": "",
  "custom_params_comments": {},
  "current_config": "",
  "current_append_line": "",
" "timeout": "50
}

This can trigger Shell script returned invalid JSON. Please check configuration. of boot_params_handler.php.

Possible fixes

parse_append_line()

awk -v label="$label" '
    /^label / {
        gsub(/\r$/, "")  # Remove trailing \r before matching
        if ($0 ~ "^label " label "$") {
            in_section=1
        } else {
            in_section=0
        }
    }
    in_section && /^  append/ {
        gsub(/\r$/, "")  # Remove trailing \r
        sub(/^  append /, "")
        print
        exit
    }
' "$cfg_file"

extract_timeout()

grep "^timeout " "$cfg_file" | awk '{print $2}' | head -n 1 | tr -d '\r'

escape_json_string() and load_comments()
echo could be optionally replaced with echo -n or printf '%s', but not really a bug as $() automatically removes the trailing newline. Examples:

"custom_params": "$(escape_json_string "$custom_params")",
...
local all_comments=$(load_comments)

@SpaceinvaderOne
Should be an issue for you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions