From: Manni H. <man...@us...> - 2008-03-05 07:34:03
|
Update of /cvsroot/popfile/engine/Classifier In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29772/Classifier Modified Files: Tag: b0_22_2 Bayes.pm Log Message: Add yet another method to deal with possible null-bytes: db_quote(). Call this function instead of the DBI version if you are going to execute your sql with do(). Index: Bayes.pm =================================================================== RCS file: /cvsroot/popfile/engine/Classifier/Bayes.pm,v retrieving revision 1.327.4.12 retrieving revision 1.327.4.13 diff -C2 -d -r1.327.4.12 -r1.327.4.13 *** Bayes.pm 4 Mar 2008 13:23:14 -0000 1.327.4.12 --- Bayes.pm 5 Mar 2008 07:34:07 -0000 1.327.4.13 *************** *** 867,871 **** if ( $t->{TYPE}->[$i] !~ /^int/i ) { $val = '' if ( !defined( $val ) ); ! $val = $self->{db__}->quote( $val ); } else { $val = 'NULL' if ( !defined( $val ) ); --- 867,871 ---- if ( $t->{TYPE}->[$i] !~ /^int/i ) { $val = '' if ( !defined( $val ) ); ! $val = $self->db_quote( $val ); } else { $val = 'NULL' if ( !defined( $val ) ); *************** *** 1187,1191 **** # word), the bucket id in the buckets table (which must exist) ! $word = $self->{db__}->quote($word); my $result = $self->{db__}->selectrow_arrayref( --- 1187,1191 ---- # word), the bucket id in the buckets table (which must exist) ! $word = $self->db_quote($word); my $result = $self->{db__}->selectrow_arrayref( *************** *** 3940,3943 **** --- 3940,3967 ---- #---------------------------------------------------------------------------- # + # db_quote + # + # Quote a string for use in a sql statement. Before calling DBI::quote on the + # string the string is also checked for any null-bytes. + # + # $string The string that should be quoted. + # + # returns the quoted string without any possible null-bytes + #---------------------------------------------------------------------------- + sub db_quote { + my $self = shift; + my $string = shift; + + if ( $string =~ s/\x00//g ) { + my ( $package, $file, $line ) = caller( 1 ); + $self->log( 0, "Found null-byte in string $string. Called from package '$package' ($file), line $line." ); + } + + return $self->{db__}->quote( $string ); + } + + + #---------------------------------------------------------------------------- + # # validate_sql_prepare_and_execute # |