Bug in Constants.pm causes 500 error when running agent
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OCS Inventory: Server |
New
|
Undecided
|
Unassigned |
Bug Description
I'm running OCS Inventory version 1.3.2 on CentOS Linux, 5.4; the
package comes from the Fedora EPEL project. The client is version
1.0.1 (yes, that's old, but I'm having unrelated problems with version
1.1.2 on CentOS, and from what I can see the problem isn't related to
the client).
When I run the OCS Inventory client and point it at the server, I get
a 500 error from Apache and this message logged in Apache's error_log:
----
DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '|CHECKSUM|1),
----
(Actual hostnames deleted.) I added some debugging statements to
Hardware.pm, and here's a bit more context from the query
being run:
----
UPDATE hardware SET USERAGENT=
----
The relevant bit of Hardware.pm is:
----
$dbh->do("UPDATE hardware SET USERAGENT=
----
In turn, CHECKSUM_MAX_VALUE is defined in
Ocsinventory/
----
my $checksum_max_value = &get_checksum();
use constant CHECKSUM_MAX_VALUE => $checksum_
[snip]
sub get_checksum {
my $checksum;
for my $section (keys %DATA_MAP){
$checksum|
}
return $checksum;
}
----
By adding more debugging statements, I figured out that the subroutine
get_checksum() *was* returning a sane value (262143), but the "use
constant" statement was *not* using it. This problem can be reduced
to the test case:
----
$ perl -e'$bar = &get_bar(); print "\$bar == |$bar|\n"; use constant FOO => $bar; print "FOO == |" . FOO . "|\n"; sub get_bar { return 1;}'
$bar == |1|
FOO == ||
----
The problem appears to be that a "use constant" statement is
evaluated/set at *compile* time, and the variable assignment is done
at *run* time. This PerlMonks thread has more details:
http://
I'm not sure what the correct solution would be, but a stupid
workaround for me is just to insert this into Hardware.pm:
use constant CHECKSUM_MAX_VALUE => 262143;
Thanks very much, and please let me know if you need any further information.
affects: | ocsinventory-contact → ocsinventory-server |