Skip to content

mdiag.sh can produce invalid JSON #70

@adamchel

Description

@adamchel

I was working with some mdiag.sh output and one of the files contained the following JSON document where "[ESC]" was actually an 0x1B control character.

{
    "ref" : "",
    "host" : "REDACTED",
    "tag" : { "$date" : "2017-09-11T12:50:32.323-0400" },
    "version" : "2.0.4",
    "section" : "timedatectl",
    "ts" : {
        "start" : { "$date" : "2017-09-11T12:51:22.987-0400" },
          "end" : { "$date" : "2017-09-11T12:51:23.015-0400" } },
    "command" : [ "timedatectl" ],
    "rc" : 0,
    "output" : [
        "      Local time: Mon 2017-09-11 12:51:23 EDT",
        "  Universal time: Mon 2017-09-11 16:51:23 UTC",
        "        RTC time: Mon 2017-09-11 12:51:23",
        "       Time zone: America/New_York (EDT, -0400)",
        "     NTP enabled: yes",
        "NTP synchronized: yes",
        " RTC in local TZ: yes",
        "      DST active: yes",
        " Last DST change: DST began at",
        "                  Sun 2017-03-12 01:59:59 EST",
        "                  Sun 2017-03-12 03:00:00 EDT",
        " Next DST change: DST ends (the clock jumps one hour backwards) at",
        "                  Sun 2017-11-05 01:59:59 EDT",
        "                  Sun 2017-11-05 01:00:00 EST",
        "",
        "[ESC]�[1;39mWarning: The system is configured to read the RTC time in the local time zone.",
        "         This mode can not be fully supported. It will create various problems",
        "         with time zone changes and daylight saving time adjustments. The RTC",
        "         time is never updated, it relies on external facilities to maintain it.",
        "         If at all possible, use RTC in UTC by calling",
        "         'timedatectl set-local-rtc 0'�[ESC][0m." ],
    "error" : null
}

Per the JSON specification, control characters are not allowed in strings, so this could probably be fixed by just having the script omit control characters from the JSON output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions