Skip to content

Commit

Permalink
ommysql bugfix: potential segfault on database error
Browse files Browse the repository at this point in the history
Due to an invalid code path, ommysql may cause a segfault if database
transactions fail into a specific way. The main trigger is a totally
irrecoverrable database error which can lead to premature connection
close, which is not checked for in all recover code.

This was detected in a setting where a stored procedure is called that
rolls back a transaction in itself.

This patch fixes the issue.

closes #5288
  • Loading branch information
rgerhards committed Dec 12, 2023
1 parent ea86c9d commit 1e45801
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions plugins/ommysql/ommysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,15 @@ CODESTARTcommitTransaction
if(iRet != RS_RET_OK
&& iRet != RS_RET_DEFER_COMMIT
&& iRet != RS_RET_PREVIOUS_COMMITTED) {
if(mysql_rollback(pWrkrData->hmysql) != 0) {
DBGPRINTF("ommysql: server error: transaction could not be rolled back\n");
if(pWrkrData->hmysql == NULL) {
DBGPRINTF("ommysql: server error: hmysql is closed, transaction rollback "
"willl not be tried (it probably already happened)\n");
} else {
if(mysql_rollback(pWrkrData->hmysql) != 0) {
DBGPRINTF("ommysql: server error: transaction could not be rolled back\n");
}
closeMySQL(pWrkrData);
}
closeMySQL(pWrkrData);
FINALIZE;
}
}
Expand Down

0 comments on commit 1e45801

Please sign in to comment.