Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-487

NULL out pointers after freeing them as defensive programming

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • None
    • 3.1.10
    • Internal
    • None
    • Linux (Debian GNU/Linux 10 "buster"

    Description

      In mariadb_lib.c, the mysql_close function contains this code:

      if (mysql->net.extension)
      free(mysql->net.extension);

      mysql->host_info=mysql->user=mysql->passwd=mysql->db=0;

      /* Clear pointers for better safety */
      memset((char*) &mysql->options, 0, sizeof(mysql->options));

      if (mysql->extension)
      free(mysql->extension);

      mysql->net.pvio= 0;
      if (mysql->free_me)
      free(mysql);

      I recommend setting mysql->extension and mysql->net.extension to NULL also as a defensive programming technique. (This is already done for mysql->options.extension in the memset() call).

      This refers to https://jira.mariadb.org/browse/CONC-289 and also fixes the DBD::mysql issue reported at https://github.com/perl5-dbi/DBD-mysql/issues/306

      A patch is attached.

      Regards,

      Dianne.

      Attachments

        Activity

          This was reported in Debian as https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=966633

          georg Could you please take a look? It has a patch and everything.

          otto Otto Kekäläinen added a comment - This was reported in Debian as https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=966633 georg Could you please take a look? It has a patch and everything.
          georg Georg Richter added a comment -

          Hi Otto,

          there i s already a pull request for - unfortunately travis build is broken again, need to fix it first before I will merge pull requests.

          georg Georg Richter added a comment - Hi Otto, there i s already a pull request for - unfortunately travis build is broken again, need to fix it first before I will merge pull requests.

          Looking at the two failures for Travis-CI on latest MariaDB Connector
          C master branch
          (https://travis-ci.com/github/mariadb-corporation/mariadb-connector-c/jobs/371703398
          and https://travis-ci.com/github/mariadb-corporation/mariadb-connector-c/jobs/371703399)
          they seem to be ssl issues and not related to this issue. So I guess
          we just need to wait until thoes are solved then.

          otto Otto Kekäläinen added a comment - Looking at the two failures for Travis-CI on latest MariaDB Connector C master branch ( https://travis-ci.com/github/mariadb-corporation/mariadb-connector-c/jobs/371703398 and https://travis-ci.com/github/mariadb-corporation/mariadb-connector-c/jobs/371703399 ) they seem to be ssl issues and not related to this issue. So I guess we just need to wait until thoes are solved then.
          georg Georg Richter added a comment -

          This issue was already fixed in 3.1.10 (PR #144)

          georg Georg Richter added a comment - This issue was already fixed in 3.1.10 (PR #144)

          People

            georg Georg Richter
            dskoll Dianne Skoll
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.