[PATCH] auth: Handle the extra single-row result set of MySQL stored procedures
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 31 Aug 2020 08:25:04 +0000 (10:25 +0200)
committerChris Hofstaedtler <zeha@debian.org>
Thu, 3 Sep 2020 16:08:42 +0000 (17:08 +0100)
Gbp-Pq: Name mysqlsp.patch

modules/gmysqlbackend/smysql.cc

index 74087425e262d9462638628033df0ff56c18e238..23c48419d93067c82cb092e1085eb42850d2d333 100644 (file)
@@ -303,7 +303,10 @@ public:
         d_resnum = mysql_stmt_num_rows(d_stmt);
         // XXX: For some reason mysql_stmt_result_metadata returns NULL here, so we cannot
         // ensure row field count matches first result set.
-        if (d_resnum > 0) { // ignore empty result set
+        // We need to check the field count as stored procedure return the final values of OUT and INOUT parameters
+        // as an extra single-row result set following any result sets produced by the procedure itself.
+        // mysql_stmt_field_count() will return 0 for those.
+        if (mysql_stmt_field_count(d_stmt) > 0 && d_resnum > 0) { // ignore empty result set
           if (d_res_bind != nullptr && (err = mysql_stmt_bind_result(d_stmt, d_res_bind))) {
             string error(mysql_stmt_error(d_stmt));
             releaseStatement();