Bug #106340 contribution by Tence : Assertion failed Defining a Sys_var_mybool with NO_ARG
Submitted: 31 Jan 2022 16:04 Modified: 31 Jan 2022 16:37
Reporter: yuxiang jiang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.7 OS:Any
Assigned to: CPU Architecture:Any
Tags: sysvars bool assertion

[31 Jan 2022 16:04] yuxiang jiang
Description:
Defining a Sys_var_mybool with NO_ARG will cause  assertion failed when starting. 

I am not sure whether this assertion is proper. It seems that NO_ARG with default value is also work fine.

Maybe Sys_var_multi_enum has the same problem.

How to repeat:
From 825a066c931c7ae16b1ce8b687a5ff740e27ceb3 Mon Sep 17 00:00:00 2001
From: yuxianjiang <yuxianjiang@tencent.com>
Date: Mon, 31 Jan 2022 23:37:09 +0800
Subject: [PATCH] Test for Sys_var_mybool assertion.

---
 sql/sql_class.h | 1 +
 sql/sys_vars.cc | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/sql/sql_class.h b/sql/sql_class.h
index 056c153..7034b63 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -609,6 +609,7 @@ typedef struct system_variables
   /**
     Changes from txsql end.
   */
+  my_bool test_mybool_NO_ARG;
 } SV;

Apply this changes and run ./mtr --mem --start --manual-gdb

diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index b62ae89..49260c0 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -7124,3 +7124,12 @@ static Sys_var_charptr Sys_all_stack_path(
 /**
  Changes from txsql end.
 */
+
+my_bool test_mybool_NO_ARG=FALSE;
+static Sys_var_mybool Sys_test_mybool_NO_ARG(
+    "test_mybool_NO_ARG",
+    "Test for mybool .",
+    SESSION_VAR(test_mybool_NO_ARG), CMD_LINE(NO_ARG),
+    DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG,
+    ON_CHECK(NULL));
+
--
1.8.3.1

Suggested fix:
-    assert(getopt.arg_type == OPT_ARG || getopt.id == -1);
+    assert((getopt.arg_type == OPT_ARG || getopt.arg_type == NO_ARG)
+           || getopt.id == -1);
[31 Jan 2022 16:06] yuxiang jiang
Follow up
[31 Jan 2022 16:37] MySQL Verification Team
Hi Mr. jiang,

Thank you for your bug report.

We have analysed your logic and concluded that it is correct.

Thank you for your patch as well.

Verified as reported.
[1 Feb 2022 1:42] yuxiang jiang
contribution by Tence

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: 0001-bugfix-Assertion-failed-when-Defining-a-Sys_var_mybo.patch (application/octet-stream, text), 1.42 KiB.