https://www.mediawiki.org/wiki/Special:Code/MediaWiki/115500
Revision: 115500
Author: maxsem
Date: 2012-06-11 20:10:53 +0000 (Mon, 11 Jun 2012)
Log Message:
-----------
Final tweaks
Modified Paths:
--------------
trunk/debs/squid/redirector.c
trunk/debs/squid/test-redirector.php
Modified: trunk/debs/squid/redirector.c
===================================================================
--- trunk/debs/squid/redirector.c 2012-06-11 18:50:31 UTC (rev 115499)
+++ trunk/debs/squid/redirector.c 2012-06-11 20:10:53 UTC (rev 115500)
@@ -1,8 +1,8 @@
-/*
+/**
*
- * Squid Redirect Helper - reads from stdin, outputs 302 to
$1.m.wikipedia.org/$2
- * if original matches "^http:\\/\\/(\\w+)\\.wikipedia\\.org[:\\d]*\\/(.*)"
- * A new base url in place of m.wikipedia.org may be provided as the only
argument.
+ * Squid Redirect Helper - reads from stdin, outputs 302 to $1.m.$2.org/$3
+ * if original matches "^http:\\/\\/(\\w+)\\.<sitename>\\.org[:\\d]*\\/(.*)"
+ * A new base url in place of m.wikipedia.org may be provided as the only
argument.
*
* To compile: gcc -O3 -o redirector -lpcre redirector.c
*
@@ -19,8 +19,8 @@
#define OVECCOUNT 30 /* should be a multiple of 3 */
struct IN_BUFF {
- char *chan;
- char *url;
+ char *chan;
+ char *url;
};
int load_in_buff(char *buff, struct IN_BUFF *in_buff) {
@@ -57,13 +57,13 @@
if (argv[1] != NULL) {
char replacement_url_pattern[] = "302:%s\n";
char *command_line_url = argv[1];
- sprintf(replacement_url, replacement_url_pattern,
command_line_url);
+ sprintf(replacement_url, replacement_url_pattern,
command_line_url);
}
/* make standard output line buffered */
//setvbuf(stdout, NULL, _IOLBF, 0);
setbuf(stdout, NULL);
-
+
re = pcre_compile(
pattern, /* the pattern */
0, /* default options */
@@ -75,10 +75,10 @@
fprintf(stderr, "pcre_compile failed at offset %d: %s\n",
erroffset, error);
exit(1);
}
-
+
pe = pcre_study(re, 0, &error);
- while(fgets(buff, MAX_BUFF, stdin) != NULL) {
+ while(fgets(buff, sizeof(buff), stdin) != NULL) {
if (load_in_buff(buff, &in_buff) != 0) {
fprintf(stderr, "Error loading data %s\n", buff);
@@ -102,8 +102,8 @@
case PCRE_ERROR_NOMATCH:
printf("%s %s\n", in_buff.chan,
in_buff.url);
fflush(stdout);
-
break;
+
default:
fprintf(stderr, "Matching error %d\n",
rc);
break;
Modified: trunk/debs/squid/test-redirector.php
===================================================================
--- trunk/debs/squid/test-redirector.php 2012-06-11 18:50:31 UTC (rev
115499)
+++ trunk/debs/squid/test-redirector.php 2012-06-11 20:10:53 UTC (rev
115500)
@@ -7,7 +7,7 @@
);
$pipes = array();
-$proc = proc_open( './a.out', $descriptorspec, $pipes );
+$proc = proc_open( './redirector', $descriptorspec, $pipes );
list( $stdin, $stdout, $stderr ) = $pipes;
function closeall() {
@@ -108,7 +108,10 @@
'http://someothersite.com' => 'http://someothersite.com',
'http://someothersite.com/?foo=bar' =>
'http://someothersite.com/?foo=bar',
'http://someothersite.com/wiki/Foo' =>
'http://someothersite.com/wiki/Foo',
+
+ //test for buffer overflows
//$overflow => substr( $overflow, 0, 8251 ),
+ 'http://' . str_repeat( 'x', 25 ) . '.wikipedia.org/wiki/foo' =>
'302:http://xxxxxxxxxxxxxxxxxx.m.wikipedia.org/wiki/foo',
);
echo "Testing with preset cases...\n";
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs