200
}
201
}
202
203
+# parameters which are pathnames
204
our $project = $cgi->param('p');
205
if (defined $project) {
205
- if (!validate_input($project) ||
206
+ if (!validate_pathname($project) ||
207
!(-d "$projectroot/$project") ||
208
!(-e "$projectroot/$project/HEAD") ||
209
($export_ok && !(-e "$projectroot/$project/$export_ok")) ||
213
}
214
}
215
215
-# We have to handle those containing any characters:
216
our $file_name = $cgi->param('f');
217
+if (defined $file_name) {
218
+ if (!validate_pathname($file_name)) {
219
+ die_error(undef, "Invalid file parameter");
220
+ }
221
+}
222
+
223
our $file_parent = $cgi->param('fp');
224
+if (defined $file_parent) {
225
+ if (!validate_pathname($file_parent)) {
226
+ die_error(undef, "Invalid file parent parameter");
227
+ }
228
+}
229
230
+# parameters which are refnames
231
our $hash = $cgi->param('h');
232
if (defined $hash) {
221
- if (!validate_input($hash)) {
233
+ if (!validate_refname($hash)) {
234
die_error(undef, "Invalid hash parameter");
235
}
236
}
237
238
our $hash_parent = $cgi->param('hp');
239
if (defined $hash_parent) {
228
- if (!validate_input($hash_parent)) {
240
+ if (!validate_refname($hash_parent)) {
241
die_error(undef, "Invalid hash parent parameter");
242
}
243
}
244
245
our $hash_base = $cgi->param('hb');
246
if (defined $hash_base) {
235
- if (!validate_input($hash_base)) {
247
+ if (!validate_refname($hash_base)) {
248
die_error(undef, "Invalid hash base parameter");
249
}
250
}
251
252
our $hash_parent_base = $cgi->param('hpb');
253
if (defined $hash_parent_base) {
242
- if (!validate_input($hash_parent_base)) {
254
+ if (!validate_refname($hash_parent_base)) {
255
die_error(undef, "Invalid hash parent base parameter");
256
}
257
}
258
259
+# other parameters
260
our $page = $cgi->param('pg');
261
if (defined $page) {
262
if ($page =~ m/[^0-9]/) {
286
$project =~ s,/*[^/]*$,,;
287
}
288
# validate project
276
- $project = validate_input($project);
289
+ $project = validate_pathname($project);
290
if (!$project ||
291
($export_ok && !-e "$projectroot/$project/$export_ok") ||
292
($strict_export && !project_in_list($project))) {
307
} else {
308
$action ||= "blob_plain";
309
}
297
- $hash_base ||= validate_input($refname);
298
- $file_name ||= $pathname;
310
+ $hash_base ||= validate_refname($refname);
311
+ $file_name ||= validate_pathname($pathname);
312
} elsif (defined $refname) {
313
# we got "project.git/branch"
314
$action ||= "shortlog";
302
- $hash ||= validate_input($refname);
315
+ $hash ||= validate_refname($refname);
316
}
317
}
318
evaluate_path_info();
400
## ======================================================================
401
## validation, quoting/unquoting and escaping
402
390
-sub validate_input {
391
- my $input = shift;
403
+sub validate_pathname {
404
+ my $input = shift || return undef;
405
393
- if ($input =~ m/^[0-9a-fA-F]{40}$/) {
394
- return $input;
406
+ # no '.' or '..' as elements of path, i.e. no '.' nor '..'
407
+ # at the beginning, at the end, and between slashes.
408
+ # also this catches doubled slashes
409
+ if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
410
+ return undef;
411
}
396
- if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
412
+ # no null characters
413
+ if ($input =~ m!\0!) {
414
return undef;
415
}
399
- if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
416
+ return $input;
417
+}
418
+
419
+sub validate_refname {
420
+ my $input = shift || return undef;
421
+
422
+ # textual hashes are O.K.
423
+ if ($input =~ m/^[0-9a-fA-F]{40}$/) {
424
+ return $input;
425
+ }
426
+ # it must be correct pathname
427
+ $input = validate_pathname($input)
428
+ or return undef;
429
+ # restrictions on ref name according to git-check-ref-format
430
+ if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
431
return undef;
432
}
433
return $input;