Skip to content
This repository was archived by the owner on Sep 23, 2023. It is now read-only.

Commit 8a00958

Browse files
edg2sMatmaRex
authored andcommitted
Improve patch number validation
1 parent 561578a commit 8a00958

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

new.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,19 @@ function set_progress( float $pc, string $label ) {
128128

129129
// Iterate by reference, so that we can modify the $patches array to add new entries
130130
foreach ( $patches as &$patch ) {
131-
$patchSafe = preg_replace( '/(?!^I)[^0-9a-f]/', '', $patch );
132-
$data = gerrit_query( "changes/?q=change:$patchSafe&o=LABELS&o=CURRENT_REVISION", true );
131+
if ( !preg_match( '/^(I[0-9a-f]+|[0-9]+)$/', $patch ) ) {
132+
$patch = htmlentities( $patch );
133+
abandon( "Invalid patch number <em>$patch</em>" );
134+
}
135+
$data = gerrit_query( "changes/?q=change:$patch&o=LABELS&o=CURRENT_REVISION", true );
133136

134137
if ( count( $data ) === 0 ) {
135-
$patchSafe = htmlentities( $patchSafe );
136-
abandon( "Could not find patch <em>$patchSafe</em>" );
138+
$patch = htmlentities( $patch );
139+
abandon( "Could not find patch <em>$patch</em>" );
137140
}
138141
if ( count( $data ) !== 1 ) {
139-
$patchSafe = htmlentities( $patchSafe );
140-
abandon( "Ambiguous query <em>$patchSafe</em>" );
142+
$patch = htmlentities( $patch );
143+
abandon( "Ambiguous query <em>$patch</em>" );
141144
}
142145

143146
// get the info

0 commit comments

Comments
 (0)