Uploaded image for project: 'MariaDB Connector/C++'
  1. MariaDB Connector/C++
  2. CONCPP-29

Conector/C++ returns NULL on invalid URI instead of throwing an exception

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 0.9.2
    • 0.9.3
    • General
    • None
    • Linux CentOS 7.7

    Description

      The following code cause a core dump. This is due to the URI being badly formatted. The expected behavior would be to throw an exception.

      #include <iostream>
      #include <exception>
      #include <ConnCpp.h>
      #include <Exception.h>
       
      int main(int argc, char *argv[])
         {
         sql::Driver* driver = sql::mariadb::get_driver_instance();
         sql::Connection *conn;
         sql::Statement *stmt;
       
         try {
            conn = driver->connect("moe:3306", "user", "pwd");
            stmt = conn->createStatement();
         } catch(sql::SQLException &e) {
            std::cerr << "Exception: " << e.what() << "\n";
         }
       
         return 0;
         }
      

      The error is in MariaDbDriver.cpp at:

        Connection* MariaDbDriver::connect(const SQLString& url, Properties& props)
        {
          UrlParser* urlParser= UrlParser::parse(url, props);
       
          if (urlParser == nullptr || urlParser->getHostAddresses().empty())
          {
      ==>      return nullptr;
      

      Attachments

        Activity

          People

            Lawrin Lawrin Novitsky
            karlsson Anders Karlsson
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.