Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-39971

generate_option_list may invoke pclose() on a null pointer

    XMLWordPrintable

Details

    • Can result in hang or crash
    • When failing to invoke MariaDB Server, the program generate_option_list could crash instead of exiting with a failure status.

    Description

      I found the following warning while compiling MariaDB:

      .../extra/generate_option_list.cc: In function 'std::string call_mariadbd(const char*, const char*, const char*)':
      .../include/my_sys.h:1096:28: warning: argument 1 null where non-null expected [-Wnonnull]
       1096 | #define my_pclose(A) pclose(A)
            |                      ~~~~~~^~~
      .../extra/generate_option_list.cc:95:5: note: in expansion of macro 'my_pclose'
         95 |     my_pclose(f);
            |     ^~~~~~~~~
      In file included from .../include/my_global.h:285,
                       from .../extra/generate_option_list.cc:18:
      /usr/include/stdio.h:887:12: note: in a call to function 'int pclose(FILE*)' declared 'nonnull'
        887 | extern int pclose (FILE *__stream) __nonnull ((1));
            |            ^~~~~~
      

      The call is clearly redundant:

      mariadb-11.8.7:extra/generate_option_list.cc

      91
        FILE *f= my_popen(command.str().c_str(), "r");
      92
        if (!f)
      93
        {
      94
          perror("failed to read mariadbd output");
      95
          my_pclose(f);
      

      While man 3 pclose on my system does not say that the parameter is supposed to be a non-null return value of popen, it is kind of implied by the fact that the two functions are documented together.

      This regression could have been avoided if we enabled -Werror on CMAKE_BUILD_TYPE=RelWithDebInfo targets. Currently we only enable the equivalent /WX when targeting Microsoft Windows.

      Attachments

        Issue Links

          Activity

            People

              marko Marko Mäkelä
              marko Marko Mäkelä
              Marko Mäkelä Marko Mäkelä
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.