b5ffaecde00b0e38291f3833f1ecfdc271d7ab8a max Mon Aug 28 03:58:05 2023 -0700 hardening of jksql against sc==NULL. A crash happened at some point when running a tool from the command line. no redmine diff --git src/hg/lib/jksql.c src/hg/lib/jksql.c index 99bacfd..22d274b 100644 --- src/hg/lib/jksql.c +++ src/hg/lib/jksql.c @@ -1317,30 +1317,33 @@ /* Connect to database on default host as default user. * Return NULL (don't abort) on failure. */ { return sqlConnProfile(sqlProfileMustGet(NULL, database), database, FALSE); } static boolean sqlConnectIfUnconnected(struct sqlConnection *sc, bool abort) /* Take a yet unconnected sqlConnection object and connect it to the sql server. * returns TRUE on success, FALSE otherwise. * This allows us to have mysql connection objects with a server name, port, * database etc, but no actual mysql connection setup yet. The connection is * only done when a query comes in. This saves a lot of time, as the failover * connection object is just tracking the database changes on the main * connection, and connects only when really necessary. */ { +if (!sc) + return FALSE; + if (sc->conn!=NULL) return TRUE; char *profName = NULL; if (sc->profile) profName = sc->profile->name; struct sqlProfile *sp = sqlProfileMustGet(profName, sc->db); return (sqlConnRemoteFillIn(sc, sp, sc->db, abort, FALSE) != NULL); } struct sqlConnection *sqlConnect(char *database) /* Connect to database on default host as default user. */ { struct sqlProfile *defProf = sqlProfileMustGet(NULL, database); return sqlConnProfile(defProf, database, TRUE); } @@ -1405,31 +1408,31 @@ struct sqlConnection *sqlFailoverConn(struct sqlConnection *sc) /* Returns the failover connection of a connection or NULL. * (Needed because the sqlConnection is not in the .h file) */ { return sc->failoverConn; } bool sqlConnMustUseFailover(struct sqlConnection *sc) /* Returns true if a connection has a failover connection and * the current db does not exist on the main connection. */ { // a db that is different between the sqlConnection object and mysql means that we have // moved previously to a db that does not exist on the main connection server -if ((sc->failoverConn != NULL) && differentStringNullOk(sc->db, sc->conn->db)) +if ((sc && sc->failoverConn != NULL) && differentStringNullOk(sc->db, sc->conn->db)) { monitorPrint(sc, "SQL_MAINCONN_DB_INVALID", "%s != %s", sc->db, sc->conn->db); return TRUE; } return FALSE; } char *sqlHostInfo(struct sqlConnection *sc) /* Returns the mysql host info for the connection, must be connected. */ { return (char *) mysql_get_host_info(sc->conn); } static struct sqlResult *sqlUseOrStore(struct sqlConnection *sc,