php / php/php-src

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

Aperta
#21,364 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Extension: snmp
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in ext/snmp/snmp.c, in php_snmp(), e segui il percorso SNMP_USE_SUFFIX_AS_KEYS | SNMP_CMD_WALK. Esamina la costruzione del suffisso, il caso della root esatta e ogni confronto che coinvolge count e vars->name_length. Il lavoro è completato quando la formattazione ridondante è stata rimossa, il comportamento delle chiavi vuote è stato deciso e coperto e gli avvisi signed/unsigned sono stati risolti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c
Ambito
networking
Tipo di issue
Refactoring
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.