forked from php/web-bugs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.php
More file actions
571 lines (487 loc) · 23.3 KB
/
report.php
File metadata and controls
571 lines (487 loc) · 23.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
<?php
use App\Repository\PackageRepository;
use App\Repository\ReasonRepository;
use App\Utils\Cache;
use App\Utils\Captcha;
use App\Utils\PatchTracker;
use App\Utils\Versions\Client;
use App\Utils\Versions\Generator;
// Obtain common includes
require_once '../include/prepend.php';
// Start session
session_start();
// Init variables
$errors = [];
$ok_to_submit_report = false;
$packageRepository = $container->get(PackageRepository::class);
$pseudo_pkgs = $packageRepository->findEnabled($_GET['project'] ?? '');
// Authenticate
bugs_authenticate($user, $pw, $logged_in, $user_flags);
$versionsClient = new Client();
$cacheDir = (defined('DEVBOX') && true === DEVBOX) ? __DIR__.'/../var/cache' : '/tmp';
$cache = new Cache($cacheDir);
$versionsGenerator = new Generator($versionsClient, $cache);
$versions = $versionsGenerator->getVersions();
// captcha is not necessary if the user is logged in
if (!$logged_in) {
$captcha = $container->get(Captcha::class);
}
$packageAffectedScript = <<<SCRIPT
<script src="$site_method://$site_url$basedir/js/package-affected.js"></script>
SCRIPT;
// Handle input
if (isset($_POST['in'])) {
$errors = incoming_details_are_valid($_POST['in'], 1, $logged_in);
// Check if session answer is set, then compare it with the post captcha value.
// If it's not the same, then it's an incorrect password.
if (!$logged_in) {
if (!isset($_SESSION['answer'])) {
$errors[] = 'Please enable cookies so the Captcha system can work';
} elseif ($_POST['captcha'] != $_SESSION['answer']) {
$errors[] = 'Incorrect Captcha';
}
if (is_spam($_POST['in']['ldesc']) ||
is_spam($_POST['in']['expres']) ||
is_spam($_POST['in']['repcode'])) {
$errors[] = 'Spam detected';
}
}
// Set auto-generated password when not supplied or logged in
if ($logged_in || $_POST['in']['passwd'] == '') {
$_POST['in']['passwd'] = uniqid();
}
// try to verify the user
$_POST['in']['email'] = $auth_user->email;
$package_name = $_POST['in']['package_name'];
if (!$errors) {
// When user submits a report, do a search and display the results before allowing them to continue.
if (!isset($_POST['preview']) && empty($_POST['in']['did_luser_search'])) {
$_POST['in']['did_luser_search'] = 1;
$where_clause = "WHERE package_name != 'Feature/Change Request'";
if (!($user_flags & BUGS_SECURITY_DEV)) {
$where_clause .= " AND private = 'N' ";
}
// search for a match using keywords from the subject
list($sql_search, $ignored) = format_search_string($_POST['in']['sdesc']);
$where_clause .= $sql_search;
$query = "SELECT * from bugdb $where_clause LIMIT 5";
$possible_duplicates = $dbh->prepare($query)->execute()->fetchAll();
if (!$possible_duplicates) {
$ok_to_submit_report = true;
} else {
response_header("Report - Confirm", $packageAffectedScript);
if (count($_FILES)) {
echo '<h1>WARNING: YOU MUST RE-UPLOAD YOUR PATCH, OR IT WILL BE IGNORED</h1>';
}
?>
<p>
Are you sure that you searched before you submitted your bug report? We
found the following bugs that seem to be similar to yours; please check
them before submitting the report as they might contain the solution you
are looking for.
</p>
<p>
If you're sure that your report is a genuine bug that has not been reported
before, you can scroll down and click the "Send Bug Report" button again to
really enter the details into our database.
</p>
<div class="warnings">
<table class="lusersearch">
<tr>
<th>Description</th>
<th>Possible Solution</th>
</tr>
<?php
foreach ($possible_duplicates as $row) {
$resolution = $dbh->prepare("
SELECT comment
FROM bugdb_comments
WHERE bug = ?
ORDER BY id DESC
LIMIT 1
")->execute([$row['id']])->fetch(\PDO::FETCH_NUM)[0];
$summary = $row['ldesc'];
if (strlen($summary) > 256) {
$summary = substr(trim($summary), 0, 256) . ' ...';
}
$bug_url = "bug.php?id={$row['id']}";
$sdesc = htmlspecialchars($row['sdesc']);
$summary = htmlspecialchars($summary);
$resolution = htmlspecialchars($resolution);
echo <<< OUTPUT
<tr>
<td colspan='2'><strong>{$row['package_name']}</strong> : <a href='{$bug_url}'>Bug #{$row['id']}: {$sdesc}</a></td>
</tr>
<tr>
<td><pre class='note'>{$summary}</pre></td>
<td><pre class='note'>{$resolution}</pre></td>
</tr>
OUTPUT;
}
echo "
</table>
</div>
";
}
} else {
// We displayed the luser search and they said it really was not already submitted, so let's allow them to submit.
$ok_to_submit_report = true;
}
if (isset($_POST['edit_after_preview'])) {
$ok_to_submit_report = false;
response_header("Report - New", $packageAffectedScript);
}
if ($ok_to_submit_report) {
$_POST['in']['reporter_name'] = $auth_user->name;
$_POST['in']['handle'] = $auth_user->handle;
// Put all text areas together.
$fdesc = "Description:\n------------\n" . $_POST['in']['ldesc'] . "\n\n";
if (!empty($_POST['in']['repcode'])) {
$fdesc .= "Test script:\n---------------\n";
$fdesc .= $_POST['in']['repcode'] . "\n\n";
}
if (!empty($_POST['in']['expres']) || $_POST['in']['expres'] === '0') {
$fdesc .= "Expected result:\n----------------\n";
$fdesc .= $_POST['in']['expres'] . "\n\n";
}
if (!empty($_POST['in']['actres']) || $_POST['in']['actres'] === '0') {
$fdesc .= "Actual result:\n--------------\n";
$fdesc .= $_POST['in']['actres'] . "\n";
}
// Bug type 'Security' marks automatically the report as private
$_POST['in']['private'] = ($_POST['in']['bug_type'] == 'Security') ? 'Y' : 'N';
$_POST['in']['block_user_comment'] = 'N';
if (isset($_POST['preview'])) {
$_POST['in']['status'] = 'Open';
$_SESSION['bug_preview'] = $_POST['in'];
$_SESSION['bug_preview']['ldesc_orig'] = $_POST['in']['ldesc'];
$_SESSION['bug_preview']['ldesc'] = $fdesc;
$_SESSION['captcha'] = $_POST['captcha'];
redirect('bug.php?id=preview');
}
$res = $dbh->prepare('
INSERT INTO bugdb (
package_name,
bug_type,
email,
sdesc,
ldesc,
php_version,
php_os,
passwd,
reporter_name,
status,
ts1,
private,
visitor_ip
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, "Open", NOW(), ?, INET6_ATON(?))
')->execute([
$package_name,
$_POST['in']['bug_type'],
$_POST['in']['email'],
$_POST['in']['sdesc'],
$fdesc,
$_POST['in']['php_version'],
$_POST['in']['php_os'],
bugs_get_hash($_POST['in']['passwd']),
$_POST['in']['reporter_name'],
$_POST['in']['private'],
$_SERVER['REMOTE_ADDR']
]
);
$cid = $dbh->lastInsertId();
$redirectToPatchAdd = false;
if (!empty($_POST['in']['patchname']) && $_POST['in']['patchname']) {
$tracker = $container->get(PatchTracker::class);
try {
$developer = !empty($_POST['in']['handle']) ? $_POST['in']['handle'] : $_POST['in']['email'];
$patchrevision = $tracker->attach($cid, 'patchfile', $_POST['in']['patchname'], $developer, []);
} catch (\Exception $e) {
$redirectToPatchAdd = true;
}
}
if (empty($_POST['in']['handle'])) {
$mailfrom = spam_protect($_POST['in']['email'], 'text');
} else {
$mailfrom = $_POST['in']['handle'];
}
$report = <<< REPORT
From: {$mailfrom}
Operating system: {$_POST['in']['php_os']}
PHP version: {$_POST['in']['php_version']}
Package: {$package_name}
Bug Type: {$_POST['in']['bug_type']}
Bug description:
REPORT;
$ascii_report = "{$report}{$_POST['in']['sdesc']}\n\n" . wordwrap($fdesc, 72);
$ascii_report.= "\n-- \nEdit bug report at ";
$ascii_report.= "{$site_method}://{$site_url}{$basedir}/bug.php?id=$cid&edit=";
list($mailto, $mailfrom, $bcc, $params) = get_package_mail($package_name, false, $_POST['in']['bug_type']);
$protected_email = '"' . spam_protect($_POST['in']['email'], 'text') . '"' . "<{$mailfrom}>";
$extra_headers = "From: {$protected_email}\n";
$extra_headers.= "X-PHP-BugTracker: {$siteBig}bug\n";
$extra_headers.= "X-PHP-Bug: {$cid}\n";
$extra_headers.= "X-PHP-Type: {$_POST['in']['bug_type']}\n";
$extra_headers.= "X-PHP-Version: {$_POST['in']['php_version']}\n";
$extra_headers.= "X-PHP-Category: {$package_name}\n";
$extra_headers.= "X-PHP-OS: {$_POST['in']['php_os']}\n";
$extra_headers.= "X-PHP-Status: Open\n";
$extra_headers.= "Message-ID: <bug-{$cid}@{$site_url}>";
if (isset($bug_types[$_POST['in']['bug_type']])) {
$type = $bug_types[$_POST['in']['bug_type']];
} else {
$type = 'unknown';
}
// provide shortcut URLS for "quick bug fixes"
$reasonRepository = $container->get(ReasonRepository::class);
list($RESOLVE_REASONS, $FIX_VARIATIONS) = $reasonRepository->findByProject($_GET['project'] ?? '');
$dev_extra = '';
$maxkeysize = 0;
foreach ($RESOLVE_REASONS as $v) {
if (!$v['webonly']) {
$actkeysize = strlen($v['title']) + 1;
$maxkeysize = (($maxkeysize < $actkeysize) ? $actkeysize : $maxkeysize);
}
}
foreach ($RESOLVE_REASONS as $k => $v) {
if (!$v['webonly']) {
$dev_extra .= str_pad("{$v['title']}:", $maxkeysize) . " {$site_method}://{$site_url}/fix.php?id={$cid}&r={$k}\n";
}
}
// mail to reporter
bugs_mail(
$_POST['in']['email'],
"$type #$cid: {$_POST['in']['sdesc']}",
"{$ascii_report}2\n",
"From: $siteBig Bug Database <$mailfrom>\n" .
"X-PHP-Bug: $cid\n" .
"X-PHP-Site: {$siteBig}\n" .
"Message-ID: <bug-$cid@{$site_url}>"
);
// mail to package mailing list
bugs_mail(
$mailto,
"[$siteBig-BUG] $type #$cid [NEW]: {$_POST['in']['sdesc']}",
$ascii_report . "1\n-- \n{$dev_extra}",
$extra_headers,
$params
);
if ($redirectToPatchAdd) {
$patchname = urlencode($_POST['in']['patchname']);
$patchemail= urlencode($_POST['in']['email']);
redirect("patch-add.php?bug_id={$cid}&patchname={$patchname}&email={$patchemail}");
}
redirect("bug.php?id={$cid}&thanks=4");
}
} else {
// had errors...
response_header('Report - Problems', $packageAffectedScript);
}
} // end of if input
$package = !empty($_REQUEST['package']) ? $_REQUEST['package'] : (!empty($package_name) ? $package_name : (isset($_POST['in']) && $_POST['in'] && isset($_POST['in']['package_name']) ? $_POST['in']['package_name'] : ''));
if (!is_string($package)) {
response_header('Report - Problems', $packageAffectedScript);
$errors[] = 'Invalid package name passed. Please fix it and try again.';
display_bug_error($errors);
response_footer();
exit;
}
if (!isset($_POST['in'])) {
$_POST['in'] = [
'package_name' => isset($_GET['package_name']) ? clean($_GET['package_name']) : '',
'bug_type' => isset($_GET['bug_type']) ? clean($_GET['bug_type']) : '',
'email' => '',
'sdesc' => '',
'ldesc' => isset($_GET['manpage']) ? clean("\n---\nFrom manual page: https://php.net/" . ltrim($_GET['manpage'], '/') . "\n---\n") : '',
'repcode' => '',
'expres' => '',
'actres' => '',
'php_version' => '',
'php_os' => '',
'passwd' => '',
];
response_header('Report - New', $packageAffectedScript);
?>
<p>
Before you report a bug, make sure to search for similar bugs using the "Bug List" link.
Also, read the instructions for <a target="top" href="how-to-report.php">how to report a bug that someone will want to help fix</a>.
</p>
<p>
If you aren't sure that what you're about to report is a bug, you should ask for help using one of the means for support
<a href="https://php.net/support.php">listed here</a>.
</p>
<p>
<strong>Failure to follow these instructions may result in your bug simply being marked as "not a bug."</strong>
</p>
<p style="background-color: #ffa;">
<strong>Documentation issues should now be reported on the <a href="https://github.com/php/doc-en/issues">php/doc-en</a> repository.</strong>
</p>
<p>Report <img src="images/pear_item.gif"><b>PEAR</b> related bugs <a href="https://pear.php.net/bugs/">here</a>.</p>
<p>
<strong>If you feel this bug concerns a security issue, e.g. a buffer overflow, weak encryption, etc, then email
<?php echo make_mailto_link("{$site_data['security_email']}?subject=%5BSECURITY%5D+possible+new+bug%21", $site_data['security_email']); ?>
who will assess the situation or use <strong>Security</strong> as bug type in the form below.</strong>
</p>
<?php
}
display_bug_error($errors);
?>
<form method="post" action="report.php?package=<?php echo htmlspecialchars($package); ?>" name="bugreport" id="bugreport" enctype="multipart/form-data">
<input type="hidden" name="in[did_luser_search]" value="<?php echo isset($_POST['in']['did_luser_search']) ? $_POST['in']['did_luser_search'] : 0; ?>">
<table class="form-holder" cellspacing="1">
<?php if ($logged_in) { ?>
<tr>
<th class="form-label_left">Your handle:</th>
<td class="form-input">
<?php echo $auth_user->handle; ?>
<input type="hidden" name="in[email]" value="<?php echo $auth_user->email; ?>">
</td>
</tr>
<?php } else { ?>
<tr>
<th class="form-label_left">Y<span class="accesskey">o</span>ur email address:<br><strong>MUST BE VALID</strong></th>
<td class="form-input">
<input type="email" size="20" maxlength="40" name="in[email]" required="required" value="<?php echo htmlspecialchars($_POST['in']['email'], ENT_COMPAT, 'UTF-8'); ?>" accesskey="o">
</td>
</th>
</tr>
<tr>
<th class="form-label_left"><span class="accesskey">P</span>assword:</th>
<td class="form-input">
<input type="password" size="20" maxlength="20" name="in[passwd]" required="required" value="<?php echo htmlspecialchars($_POST['in']['passwd'], ENT_COMPAT, 'UTF-8');?>" accesskey="p"><br>
You <strong>must</strong> enter any password here, which will be stored for this bug report.<br>
This password allows you to come back and modify your submitted bug report at a later date.
[<a href="bug-pwd-finder.php">Lost a bug password?</a>]
</td>
</tr>
<?php } ?>
<tr>
<th class="form-label_left">PHP version:</th>
<td class="form-input">
<select name="in[php_version]" required="required">
<?php show_version_options($_POST['in']['php_version']); ?>
</select>
</td>
</tr>
<tr>
<th class="form-label_left">Package affected:</th>
<td class="form-input">
<select name="in[package_name]" required="required">
<?php show_package_options($_POST['in']['package_name'], 0, htmlspecialchars($package)); ?>
</select>
</td>
</tr>
<tr>
<th class="form-label_left">Bug Type:</th>
<td class="form-input">
<select name="in[bug_type]" required="required">
<?php show_type_options($_POST['in']['bug_type'], /* deprecated */ false); ?>
</select>
</td>
</tr>
<tr>
<th class="form-label_left">Operating system:</th>
<td class="form-input">
<input type="text" size="20" maxlength="32" name="in[php_os]" value="<?php echo htmlspecialchars($_POST['in']['php_os'], ENT_COMPAT, 'UTF-8'); ?>">
</td>
</tr>
<tr>
<th class="form-label_left">Summary:</th>
<td class="form-input">
<input type="text" size="40" maxlength="79" name="in[sdesc]" required="required" value="<?php echo htmlspecialchars($_POST['in']['sdesc'], ENT_COMPAT, 'UTF-8'); ?>">
</td>
</tr>
<tr>
<th class="form-label_left">Note:</th>
<td class="form-input">
Please supply any information that may be helpful in fixing the bug:
<ul>
<li>The version number of the <?php echo $siteBig; ?> package or files you are using.</li>
<li>A short script that reproduces the problem.</li>
<li>The list of modules you compiled PHP with (your configure line).</li>
<li>Any other information unique or specific to your setup.</li>
<li>Any changes made in your php.ini compared to php.ini-dist or php.ini-recommended (<strong>not</strong> your whole php.ini!)</li>
<li>A <a href="bugs-generating-backtrace.php">gdb backtrace</a>.</li>
</ul>
</td>
</tr>
<tr>
<th class="form-label_left">
Description:
<p class="cell_note">
Put short code samples in the "Test script" section <strong>below</strong>
and upload patches <strong>below</strong>.
</p>
</th>
<td class="form-input">
<textarea cols="80" rows="15" name="in[ldesc]" wrap="soft" required="required"><?php echo htmlspecialchars($_POST['in']['ldesc'], ENT_COMPAT, 'UTF-8'); ?></textarea>
</td>
</tr>
<tr>
<th class="form-label_left">
Test script:
<p class="cell_note">
A short test script you wrote that demonstrates the bug.
Please <strong>do not</strong> post more than 20 lines of code.
If the code is longer than 20 lines, provide a URL to the source
code that will reproduce the bug.
</p>
</th>
<td class="form-input">
<textarea cols="80" rows="15" name="in[repcode]" wrap="no"><?php echo htmlspecialchars($_POST['in']['repcode'], ENT_COMPAT, 'UTF-8'); ?></textarea>
</td>
</tr>
<?php
$patchname = isset($_POST['in']['patchname']) ? $_POST['in']['patchname'] : '';
$patchfile = isset($_FILES['patchfile']['name']) ? $_FILES['patchfile']['name'] : '';
include "{$ROOT_DIR}/templates/patchform.php";
?>
<tr>
<th class="form-label_left">
Expected result:
<p class="cell_note">
Skip if irrelevant.
What do you expect to happen or see when you run the test script above?
</p>
</th>
<td class="form-input">
<textarea cols="80" rows="15" name="in[expres]" wrap="soft"><?php echo htmlspecialchars($_POST['in']['expres'], ENT_COMPAT, 'UTF-8'); ?></textarea>
</td>
</tr>
<tr>
<th class="form-label_left">
Actual result:
<p class="cell_note">
Skip if irrelevant.
This could be a <a href="bugs-generating-backtrace.php">backtrace</a> for example.
Try to keep it as short as possible without leaving anything relevant out.
</p>
</th>
<td class="form-input">
<textarea cols="80" rows="15" name="in[actres]" wrap="soft"><?php echo htmlspecialchars($_POST['in']['actres'], ENT_COMPAT, 'UTF-8'); ?></textarea>
</td>
</tr>
<?php if (!$logged_in) {
$_SESSION['answer'] = $captcha->getAnswer();
if (!empty($_POST['captcha']) && empty($ok_to_submit_report)) {
$captcha_label = '<strong>Solve this <em>new</em> problem:</strong>';
} else {
$captcha_label = 'Solve the problem:';
}
?>
<tr>
<th><?php echo $captcha_label; ?><br><?php echo htmlspecialchars($captcha->getQuestion()); ?></th>
<td class="form-input"><input type="text" name="captcha" autocomplete="off" required="required"></td>
</tr>
<?php } ?>
<tr>
<th class="form-label_left">Submit:</th>
<td class="form-input">
<input type="submit" value="Send bug report">
<input type="submit" value="Preview" name="preview">
</td>
</tr>
</table>
</form>
<?php
response_footer();