Stefan.petrea has uploaded a new change for review.
https://gerrit.wikimedia.org/r/57328
Change subject: Fixed a segfault - checks in->project for null
......................................................................
Fixed a segfault - checks in->project for null
The segfault problem was caused by urls which have no project in them.
This results in "in->project" being NULL and so a SIGSEGV occurs in
a strcmp at line 127 in filter.c
tl;dr => NULL safety checks were added
UPDATE: added test .txt file
UPDATE: merged with master
Change-Id: I02a80bb106bac9520c6b3a4bcfd1f52c0441ef44
---
A binary-segfault-search
A entry-line1.txt
M filter.c
M test.sh
4 files changed, 77 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/analytics/webstatscollector
refs/changes/28/57328/1
diff --git a/binary-segfault-search b/binary-segfault-search
new file mode 100755
index 0000000..5afc985
--- /dev/null
+++ b/binary-segfault-search
@@ -0,0 +1,62 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+=head1 SEGFAULT-KO v0.1
+
+So let's suppose you have a C utility that reads Squid logs and it segfaults
on some entries for whatever reasons.
+This does binary search on a big stream to nail down a squid log line that
causes segmentation faults
+
+=cut
+
+my $segfaulting_file = "s";
+my $L = 0;
+my $R = 7266786; #`cat $segfaulting_file | wc -l`;
+my $M;
+my $binary = "./filter";
+
+while ($L < $R) {
+ $M = int(($L+$R)/2);
+ # head argument for right side
+ my $HL = $M;
+ # tail argument for right side
+ my $TL = $M-$L;
+ # head argument for left side
+ my $HR = $R;
+ # tail argument for left side
+ my $TR = $R-$M;
+
+ print "M=$M L=$L R=$R\n";
+ my $go_left ;
+ my $go_right;
+ my $cmd_R = "cat $segfaulting_file | head -$HR | tail -$TR | $binary >
/dev/null;";
+ my $cmd_L = "cat $segfaulting_file | head -$HL | tail -$TL | $binary >
/dev/null;";
+
+ print "\nRunning $cmd_R\n";
+ `$cmd_R`;
+ #`./a.out $M $R`;
+ print "RETVAL=$?\n";
+ $go_right = ($? > 30000); # right side caused SEGFAULT
+ `rm core`;
+ print "\nRunning $cmd_L\n";
+ `$cmd_L`;
+ print "RETVAL=$?\n";
+ #`./a.out $L $M`;
+ $go_left = ($? > 30000); # left side caused SEGFAULT
+ `rm core`;
+
+ if( $L == $R ) {
+ last;
+ }elsif ( $go_left ) {
+ print "GO left L=$L R=$R\n";
+ $R = $M ;
+ }elsif ( $go_right ) {
+ print "GO right L=$L R=$R\n";
+ $L = $M+1;
+ };
+};
+
+
+# the loop stopped because $L==$R==$M , so we just print out $M
+print "Segfault caused by line $M\n";
+
diff --git a/entry-line1.txt b/entry-line1.txt
new file mode 100644
index 0000000..9373990
--- /dev/null
+++ b/entry-line1.txt
@@ -0,0 +1 @@
+cp1041.eqiad.wmnet 265659460 2013-02-08T00:52:17 0.000059843
0.0.0.0 -/413 434 GET
http://-/wiki/%E7%AC%AC%E4%B8%89%E6%AC%A1%E4%B8%AD%E4%B8%9C%E6%88%98%E4%BA%89
- text/html; charset=utf-8 - - - - -
diff --git a/filter.c b/filter.c
index 329f522..907636c 100644
--- a/filter.c
+++ b/filter.c
@@ -124,6 +124,11 @@
in->language=HEAD;
in->project=FIELD;
+ if(!in->language ||
+ !in->project )
+ return false;
+
+
if(!strcmp(in->project,"m")) {
in->project = "m.wikipedia";
in->title = in->language;
diff --git a/test.sh b/test.sh
index 9e1a7e2..8cf9c7a 100755
--- a/test.sh
+++ b/test.sh
@@ -19,4 +19,13 @@
echo "Test2: Big fields in filter FAILED";
fi
+TEST_PROJECT_EMPTY=`cat entry-line1.txt | ./filter | wc -l`;
+if [ $? -ne 139 -a $TEST_PROJECT_EMPTY -eq 0 ]; then
+ echo "Test3: in->project is empty PASSED";
+else
+ echo "Test3: in->project is empty FAILED";
+fi
+
+
+# test
--
To view, visit https://gerrit.wikimedia.org/r/57328
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I02a80bb106bac9520c6b3a4bcfd1f52c0441ef44
Gerrit-PatchSet: 1
Gerrit-Project: analytics/webstatscollector
Gerrit-Branch: master
Gerrit-Owner: Stefan.petrea <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits