Changeset: fe0f9933cd85 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/fe0f9933cd85 Modified Files: monetdb5/mal/mal_authorize.c monetdb5/mal/mal_session.c sql/backends/monet5/sql_user.c Branch: userprofile Log Message:
fix some leaks diffs (219 lines): diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c --- a/monetdb5/mal/mal_authorize.c +++ b/monetdb5/mal/mal_authorize.c @@ -430,6 +430,7 @@ AUTHcheckCredentials( str pwd = NULL; str hash = NULL; oid p = oid_nil; + str passValue = NULL; // BATiter passi; if (cntxt) @@ -457,9 +458,9 @@ AUTHcheckCredentials( // load password from users tbl if (authCallbackCntx.get_user_password && cntxt) - tmp = authCallbackCntx.get_user_password(cntxt, username); + passValue = authCallbackCntx.get_user_password(cntxt, username); - if (strNil(tmp)) { + if (strNil(passValue)) { throw(INVCRED, "checkCredentials", INVCRED_INVALID_USER " '%s'", username); } @@ -468,7 +469,8 @@ AUTHcheckCredentials( // tmp = (str)BUNtvar(passi, p); // assert (tmp != NULL); /* decypher the password (we lose the original tmp here) */ - tmp = AUTHdecypherValue(&pwd, tmp); + tmp = AUTHdecypherValue(&pwd, passValue); + GDKfree(passValue); // bat_iterator_end(&passi); if (tmp) return tmp; diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c --- a/monetdb5/mal/mal_session.c +++ b/monetdb5/mal/mal_session.c @@ -173,12 +173,15 @@ static str MSserveClient(Client cntxt); static inline void -cleanUpScheduleClient(bstream *fin, stream *fout, str command, str err) +cleanUpScheduleClient(Client c, bstream *fin, stream *fout, str command, str err) { - if (err) - freeException(err); + if(c) { + MCfreeClient(c); + c = NULL; + } exit_streams(fin, fout); GDKfree(command); + freeException(err); } @@ -296,22 +299,25 @@ MSscheduleClient(str command, str challe else mnstr_printf(fout, "!maximum concurrent client limit reached " "(%d), please try again later\n", MAL_MAXCLIENTS); - return cleanUpScheduleClient(fin, fout, command, NULL); + return cleanUpScheduleClient(NULL, fin, fout, command, NULL); } Scenario scenario = findScenario("sql"); - scenario->initClientCmd(c); + if ((msg = scenario->initClientCmd(c)) != MAL_SUCCEED) { + mnstr_printf(fout, "!%s\n", msg); + return cleanUpScheduleClient(c, fin, fout, command, msg); + } /* access control: verify the credentials supplied by the user, * no need to check for database stuff, because that is done per * database itself (one gets a redirect) */ if ((msg = AUTHcheckCredentials(&uid, c, user, passwd, challenge, algo)) != MAL_SUCCEED) { mnstr_printf(fout, "!%s\n", msg); - return cleanUpScheduleClient(fin, fout, command, msg); + return cleanUpScheduleClient(c, fin, fout, command, msg); } if((msg = scenario->exitClientCmd(c)) != MAL_SUCCEED) { mnstr_printf(fout, "!%s\n", msg); - return cleanUpScheduleClient(fin, fout, command, msg); + return cleanUpScheduleClient(c, fin, fout, command, msg); } - MCfreeClient(c); + cleanUpScheduleClient(c, NULL, NULL, NULL, NULL); } diff --git a/sql/backends/monet5/sql_user.c b/sql/backends/monet5/sql_user.c --- a/sql/backends/monet5/sql_user.c +++ b/sql/backends/monet5/sql_user.c @@ -92,6 +92,7 @@ setUserPassword(mvc *m, oid rid, str val { str err = NULL; str hash = NULL; + int res; if (is_oid_nil(rid)) { (void) sql_error(m, 02, SQLSTATE(42000) "setUserPassword: invalid user"); return LOG_ERR; @@ -108,13 +109,16 @@ setUserPassword(mvc *m, oid rid, str val if ((err = AUTHcypherValue(&hash, value)) != MAL_SUCCEED) { (void) sql_error(m, 02, SQLSTATE(42000) "setUserPassword: %s", getExceptionMessage(err)); freeException(err); + GDKfree(hash); return LOG_ERR; } sql_trans *tr = m->session->tr; sqlstore *store = m->session->tr->store; sql_table *users = getUsersTbl(m); - return store->table_api.column_update_value(tr, find_sql_column(users, USER_PASSWORD_COLUMN), rid, hash); + res = store->table_api.column_update_value(tr, find_sql_column(users, USER_PASSWORD_COLUMN), rid, hash); + GDKfree(hash); + return res; } @@ -123,6 +127,7 @@ changeUserPassword(mvc *m, oid rid, str { str err = NULL; str hash = NULL; + str passValue = NULL; if (is_oid_nil(rid)) { (void) sql_error(m, 02, SQLSTATE(42000) "changeUserPassword: invalid user"); return LOG_ERR; @@ -133,15 +138,19 @@ changeUserPassword(mvc *m, oid rid, str } if (oldpass) { // validate old password match - if ((err = AUTHdecypherValue(&hash, getUserPassword(m, rid))) != MAL_SUCCEED) { + if ((err = AUTHdecypherValue(&hash, passValue=getUserPassword(m, rid))) != MAL_SUCCEED) { (void) sql_error(m, 02, SQLSTATE(42000) "changeUserPassword: %s", getExceptionMessage(err)); freeException(err); + GDKfree(passValue); return LOG_ERR; } + GDKfree(passValue); if (strcmp(oldpass, hash) != 0) { (void) sql_error(m, 02, SQLSTATE(42000) "changeUserPassword: password mismatch"); + GDKfree(hash); return LOG_ERR; } + GDKfree(hash); } return setUserPassword(m, rid, newpass); } @@ -375,6 +384,8 @@ monet5_create_user(ptr _mvc, str user, s if ((err = AUTHGeneratePasswordHash(&hash, pwd)) != MAL_SUCCEED) { if (schema_buf) GDKfree(schema_buf); + if (!enc) + free(pwd); throw(MAL, "sql.create_user", SQLSTATE(42000) "create backend hash failure"); } @@ -383,15 +394,17 @@ monet5_create_user(ptr _mvc, str user, s if ((log_res = store->table_api.table_insert(m->session->tr, db_user_info, &user, &fullname, &schema_id, &schema_path, &max_memory, &max_workers, &optimizer, &default_role_id, &hash))) { if (!enc) free(pwd); - if (schema_buf) - GDKfree(schema_buf); + GDKfree(schema_buf); + GDKfree(hash); throw(SQL, "sql.create_user", SQLSTATE(42000) "Create user failed%s", log_res == LOG_CONFLICT ? " due to conflict with another transaction" : ""); } + // clean up + GDKfree(schema_buf); + GDKfree(hash); + if ((log_res = store->table_api.table_insert(m->session->tr, auths, &user_id, &user, &grantorid))) { if (!enc) free(pwd); - if (schema_buf) - GDKfree(schema_buf); throw(SQL, "sql.create_user", SQLSTATE(42000) "Create user failed%s", log_res == LOG_CONFLICT ? " due to conflict with another transaction" : ""); } @@ -401,15 +414,11 @@ monet5_create_user(ptr _mvc, str user, s case -1: if (!enc) free(pwd); - if (schema_buf) - GDKfree(schema_buf); throw(SQL,"sql.create_user",SQLSTATE(HY013) MAL_MALLOC_FAIL); case -2: case -3: if (!enc) free(pwd); - if (schema_buf) - GDKfree(schema_buf); throw(SQL,"sql.create_user",SQLSTATE(42000) "Update schema authorization failed due to transaction conflict"); default: break; @@ -424,8 +433,6 @@ monet5_create_user(ptr _mvc, str user, s c->user = grant_user; if (!enc) free(pwd); - if (schema_buf) - GDKfree(schema_buf); return ret; } @@ -581,8 +588,10 @@ monet5_create_privileges(ptr _mvc, sql_s if ((err = AUTHGeneratePasswordHash(&hash, password)) != MAL_SUCCEED) { TRC_CRITICAL(SQL_TRANS, "generate password hash failure"); freeException(err); + free(password); return ; } + free(password); char *fullname = "MonetDB Admin"; char *schema_path = default_schema_path; @@ -594,6 +603,7 @@ monet5_create_privileges(ptr _mvc, sql_s store->table_api.table_insert(m->session->tr, uinfo, &username, &fullname, &schema_id, &schema_path, &max_memory, &max_workers, &optimizer, &default_role_id, &hash); + GDKfree(hash); } static int _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org