mongodb / mongodb/support-tools

mdiag.sh can produce invalid JSON

Open
#70 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
140
Forks
154
Avg merge
3d 22h
Merged PRs (30d)
2

Description

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]Warning: 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'SC][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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate mdiag.sh and trace how command output is assembled into JSON, starting with the handling of control characters in captured output. Reproduce the issue with output containing the shown escape sequences, then verify that the generated document is valid JSON and preserves the intended readable text.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.