php / php/php-src

ext/snmp: minor cleanup in suffix-as-keys walk path

オープン
#21,364 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

Extension: snmp
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Three pre-existing issues in the SNMP_USE_SUFFIX_AS_KEYS | SNMP_CMD_WALK code path in php_snmp() (ext/snmp/snmp.c), noticed while reviewing #21341.

1. Redundant snprint_objid call

snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length); // writes full OID
if (rootlen <= vars->name_length && snmp_oid_compare(root, rootlen, vars->name, rootlen) == 0) {
    // snprintf loop overwrites buf2 entirely with the suffix

When the if condition is true (the normal walk case), buf2 is written twice and the snprint_objid result is discarded. The call only has effect as a fallback when the condition fails — but in that case SUFFIX_AS_KEYS mode silently returns a full OID as the key, mixing formats in the result array.

Suggestion: move the snprint_objid call into the else branch so it only runs when needed.

2. Empty-suffix key collision

When rootlen == vars->name_length (exact match on the walk root OID), the while loop never executes, pos stays 0, and buf2[0] = '\0'. The entry is added with key "". Multiple such OIDs would clobber each other in the returned array.

Worth deciding whether this case should be excluded, use the full OID as fallback, or is simply impossible in practice (in which case an assertion would document the invariant).

3. int count signed/unsigned comparison

count is declared int at line 111 but compared against vars->name_length (size_t) throughout the function, producing -Wsign-compare warnings. Changing to size_t is mechanical but touches multiple loop sites across the function.

Happy to send a PR covering all three if the approach looks reasonable.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

ext/snmp/snmp.c の php_snmp() から開始し、SNMP_USE_SUFFIX_AS_KEYS | SNMP_CMD_WALK のパスを追ってください。サフィックスの構築、exact-root のケース、count と vars->name_length が関係するすべての比較を確認してください。冗長なフォーマット処理が削除され、空のキーの動作が決定されてカバーされ、signed/unsigned の警告が対処されていれば完了です。

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

評価

技術スタック
c
領域
networking
issue の種類
リファクタリング
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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