Malformed local configuration is silently accepted and can be overwritten

クローズ 初心者向け
#615 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #616 @aniket866 による — マージされずにクローズ

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go
領域
cli

調査の方向性

pkg/config/localconfig.go の103〜112行目付近から始めてください。ここでは UnmarshalLocalFile のエラーが無視され、ゼロ値の設定が検証されています。次に416〜421行目付近を確認してください。ここでは watch パスが unmarshal の失敗時に空の設定を返しています。unmarshal の失敗時にはエラーを返すようにし、os.IsNotExist の分岐は残してください。メインファイルまたは watch ファイルの形式が不正な場合に YAML のエラーが発生し、ファイルが変更されないこと、そして両方のケースがテストで網羅されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Describe the bug
Malformed local configuration is silently accepted and can be overwritten

Evidence: pkg/config/localconfig.go:103-112 calls UnmarshalLocalFile, but does not return when that call fails; it proceeds to validate the zero-value config. The watch equivalent at :416-421 returns &config, nil even when unmarshalling fails.

Impact: A truncated or manually edited config file can be treated as an empty configuration instead of producing an error. Commands may then overwrite the corrupted file, losing contexts, servers, and cached credentials; a malformed watch file can silently erase watch entries.

steps to reproduce:

Run each command separately, pressing Enter after each command.

  1. Create a malformed main configuration file:

    set "CFG=%TEMP%\microcks-config.yaml"
    echo current-context: [broken> "%CFG%"
    type "%CFG%"
    

    The file should contain:

    current-context: [broken
    
  2. Run:

    go run . --config "%CFG%" context
    
  3. Observe that no YAML parse error is reported. The command instead reports that no contexts are defined, treating the malformed file as an empty configuration.

  4. Save a copy and compare the file after any command that writes local configuration:

    copy /y "%CFG%" "%CFG%.before"
    fc "%CFG%.before" "%CFG%"
    
  5. Repeat with a malformed watch configuration:

    set "MICROCKS_CONFIG_DIR=%TEMP%\microcks-malformed"
    mkdir "%MICROCKS_CONFIG_DIR%" 2>nul
    echo entries: [broken> "%MICROCKS_CONFIG_DIR%\watch"
    type "%MICROCKS_CONFIG_DIR%\watch"
    go run ./watcher
    

    The watcher should report a YAML parsing error. On the affected code, it starts with an empty watch configuration instead.

Suggested fix: Immediately return a typed environment/configuration error when unmarshalling fails, while preserving the existing os.IsNotExist behavior. Add tests for malformed main and watch files and verify the files remain unchanged after the failed read.

Image
主要言語
Go
スター
59
フォーク
75
平均マージ
4日 5時間
マージ済み PR(30日)
15

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microcks/microcks-cli のほかの issue

microcks/microcks-cli の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。