The fix

The fix:

$ cvs di -ub port.pm
Index: port.pm
===================================================================
RCS file: /home/repositories/freshports-1/scripts/port.pm,v
retrieving revision 1.52
diff -u -b -r1.52 port.pm
--- port.pm     6 Jun 2008 18:13:41 -0000       1.52
+++ port.pm     10 Aug 2008 21:09:51 -0000
@@ -160,6 +160,7 @@
                # we are updating

                # NOTE: NULLIfEmpty invokes db_escape
+               # these items were escaped here because I thought it was a problem not assigning them to a variable.
                $is_interactive_alt  = FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{is_interactive});
                $expiration_date_alt = FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{expiration_date});
                $not_for_archs_alt   = FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{not_for_archs});
@@ -176,21 +177,21 @@
        revision          = " . $dbh->quote($this->{revision})                                                                           . ",
        maintainer        = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{maintainer}))               . ",
        homepage          = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{homepage})               . ",
-       master_sites      = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{master_sites}))             . ",
+       master_sites      = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{master_sites})           . ",
        extract_suffix    = " . $dbh->quote($this->{package_exists})                                                     . ",
-       depends_build     = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{depends_build}))    . ",
-       depends_run       = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{depends_run}))              . ",
-       depends_lib       = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{depends_lib}))              . ",
-       forbidden         = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{forbidden}))                . ",
-       broken            = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{broken}))                   . ",
-       deprecated        = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{deprecated}))               . ",
-       ignore            = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{ignore}))                   . ",
-       master_port       = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{master_port}))              . ",
-       latest_link       = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{latest_link}))              . ",
-       no_latest_link    = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{no_latest_link}))   . ",
-       no_package        = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{no_package}))               . ",
-       package_name      = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{package_name}))             . ",
-       portepoch         = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{portepoch}))                . ",
+       depends_build     = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{depends_build})          . ",
+       depends_run       = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{depends_run})            . ",
+       depends_lib       = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{depends_lib})            . ",
+       forbidden         = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{forbidden})              . ",
+       broken            = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{broken})                 . ",
+       deprecated        = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{deprecated})             . ",
+       ignore            = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{ignore})                 . ",
+       master_port       = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{master_port})            . ",
+       latest_link       = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{latest_link})            . ",
+       no_latest_link    = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{no_latest_link})         . ",
+       no_package        = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{no_package})             . ",
+       package_name      = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{package_name})           . ",
+       portepoch         = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{portepoch})              . ",
        restricted        = " . $restricted_alt                                                           . ",
        no_cdrom          = " . $no_cdrom_alt                                                             . ",
        expiration_date   = " . $expiration_date_alt                                                                                                             . ",
@@ -198,7 +199,8 @@
        only_for_archs    = " . $only_for_archs_alt                                                       . ",
        not_for_archs     = " . $not_for_archs_alt                                                        . ",
        showconfig        = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{showconfig})             . ",
-       categories        = " . FreshPorts::Utilities::db_escape($dbh->quote($this->{categories}));
+       categories        = " . FreshPorts::Utilities::NULLIfEmpty($dbh, $this->{categories});
+

                # we don't always have this value, so we don't change it....
                if (defined($this->{last_commit_id})) {

Why do the above changes work? Because NullIfEmpty() checks for a NULL value before escaping the value.

sub NULLIfEmpty {
    my $dbh   = shift;
    my $value = shift;

    my $result = undef;

    if (!defined($value) || $value eq '') {
        $result = 'NULL';
    } else {
        $result = db_escape($dbh->quote($value));
    }

    return $result;
}
Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Comment

Scroll to Top