P4: Standalone web API leaks the parsed body of every request

オープン 初心者向け
#7,969 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

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

調査の方向性

code/network/stand_gui-unix.cpp のリクエストハンドラから始め、json_loads が context.requestEntity を設定している箇所と、そのポインタがどこで解放されているかを確認してください。-DGCC_ENABLE_ADDRESS_SANITIZER=ON を指定してビルドし、スタンドアロンサーバーを起動して、POST /api/1/chat リクエストを複数回送信します。AddressSanitizer が Web API からのリークを報告しなければ完了です。issue には修正案が3つ挙げられています。すべての経路でエンティティを解放する、最もシンプルなものを選んでください。

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

説明

Problem

This is minor: a small leak on a server that stays up a long time.

The standalone server's web API never frees the parsed body of a request. Every request with a body (for example each chat message sent from the web panel) leaks a few hundred bytes, so a long-running server with an active panel slowly grows.

Steps to reproduce

  1. Build current master (8afa31842) with -DGCC_ENABLE_ADDRESS_SANITIZER=ON on Linux.
  2. Start a standalone server with MediaVPs 5.0.2 and its web panel.
  3. Send 20 chat messages through the web API (POST /api/1/chat with {"message": "..."}), then stop the server.

Expected vs. actual behavior

Expected: no leaks from the web API.

Actual: AddressSanitizer reports leaks of 21 objects each (one per request with a body) allocated inside json_loads, called from the request handler in code/network/stand_gui-unix.cpp.

Proposed fixes

  1. Call json_decref(context.requestEntity) after the handler returns (it accepts NULL, so no check is needed).
  2. Give the request context a destructor that releases the entity, so every path frees it.
  3. Parse into a holder that frees itself (a small RAII wrapper around the jansson pointer) and pass handlers a borrowed pointer.
主要言語
C++
スター
488
フォーク
184
平均マージ
6日 1分
マージ済み PR(30日)
42

環境構築

このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

scp-fs2open/fs2open.github.com のほかの issue

scp-fs2open/fs2open.github.com の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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