Bug #47548 hostname.cc: ip_to_hostname(): DEBUG_ASSERT err_status must fail
Submitted: 23 Sep 2009 11:33 Modified: 3 Oct 2009 10:10
Reporter: Jørgen Austvik Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S3 (Non-critical)
Version:mysql-5.1-telco-7.0 OS:Any
Assigned to: Frazer Clement CPU Architecture:Any

[23 Sep 2009 11:33] Jørgen Austvik
Description:
hostname.cc: ip_to_hostname()

1. We have an uninitialized bool:
297: bool err_status;
(we then use variables with the same name in smaller scopes, and return it, but never write to this variable)

2. We then assert that this variable is false
490: DBUG_ASSERT(!err_status);

Asserting on an uninitialized value is bound to fail.

3. We then assert that this variable is true:
530: DBUG_ASSERT(err_status);

If the previous assert didn't fail, this should do it :)

4. In the end (after reading the value), we actually set it:

544: err_status= add_hostname(ip_key, *hostname);
551: err_status= add_hostname(ip_key, NULL);

How to repeat:
Inspect the code

(Personally, I compiled with debug and set up replication between two clusters and somewhat got this code to run and therefore dump core.)

Suggested fix:
- Initialize the variable to false
- Remove the two DBUG_ASSERT's
- Grep for similar mistakes or run through static code analyzers that catch reading uninitialized variables
[24 Sep 2009 6:24] Susanne Ebrecht
Which code tree did you use?
[24 Sep 2009 6:53] Jørgen Austvik
Hi, Susanne. 

mysql-5.1-telco-7.0, that will probably be 7.0.8.
[24 Sep 2009 10:30] Sveta Smirnova
Thank you for the report.

Verified as described using code analysis.
[1 Oct 2009 12:15] Frazer Clement
Proposed patch, aligning with implementation in mysql-next

Attachment: bug47548.patch (text/x-patch), 2.18 KiB.

[2 Oct 2009 18:33] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/85588

3071 Frazer Clement	2009-10-02
      Bug#47548 : hostname.cc: ip_to_hostname(): DEBUG_ASSERT err_status must fail
      modified:
        sql/hostname.cc
[2 Oct 2009 19:12] Bugs System
Pushed into 5.1.39-ndb-7.1.0 (revid:frazer@mysql.com-20091002184335-8ue584ev62lh1eoh) (version source revid:frazer@mysql.com-20091002184335-8ue584ev62lh1eoh) (merge vers: 5.1.39-ndb-7.1.0) (pib:11)
[3 Oct 2009 10:10] Jon Stephens
Documented bugfix in the NDB-7.0.9 changelog as follows:

        In some cases, the MySQL Server tried to use an error status
        whose value had never been set. The problem in the code that
        caused this, in hostname.cc, manifested when using debug builds
        in MySQL Cluster replication.

        This fix brings MySQL Cluster's error handling in hostname.cc 
        in line with what is implemented in MySQL 5.4.

Closed.