Skip to content

Commit e4bdee5

Browse files
committed
MDEV-36453 UBSAN: main.mysqltest - runtime error: null pointer
..passed as argument 2, which is declared to never be null (dynstr_append_mem). dynstr_append_mem, uses memcpy to append to the string which in the glibc library is declared to not take null string as the src. Defensively we declare dynstr_append_mem to not take a null argument too. mariadb-test, to prevent it calling dynstr_append_mem with a null mtr variable value, one that hasn't been initialized, we return an error if the value is null. The result of this is the $6 in the test case is never assigned a value and would error. With this resolved, strchr, if the string isn't found, a null pointer is returned. UBSAN will complain both about incrementing a pointer beyond the boundary, and also incrementing if it is null.
1 parent 7efbb0d commit e4bdee5

4 files changed

Lines changed: 5 additions & 9 deletions

File tree

client/mysqltest.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,12 +1534,12 @@ void do_eval(DYNAMIC_STRING *query_eval, const char *query,
15341534
}
15351535
else
15361536
{
1537-
if (!(v= var_get(p, &p, 0, 0)))
1537+
if (!(v= var_get(p, &p, 0, 0)) || !v->str_val)
15381538
{
15391539
report_or_die( "Bad variable in eval");
15401540
DBUG_VOID_RETURN;
15411541
}
1542-
dynstr_append_mem(query_eval, v->str_val, v->str_val_len);
1542+
dynstr_append_mem(query_eval, v->str_val, v->str_val_len);
15431543
}
15441544
break;
15451545
case '\\':
@@ -9228,8 +9228,9 @@ void do_block(enum block_cmd cmd, struct st_command* command)
92289228

92299229
/* Parse and evaluate test expression */
92309230
expr_start= strchr(p, '(');
9231-
if (!expr_start++)
9231+
if (!expr_start)
92329232
die("missing '(' in %s", cmd_name);
9233+
expr_start++;
92339234

92349235
while (my_isspace(charset_info, *expr_start))
92359236
expr_start++;

include/my_sys.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str,
861861
size_t init_alloc,size_t alloc_increment);
862862
extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append);
863863
my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append,
864-
size_t length);
864+
size_t length) __attribute__((nonnull(2)));
865865
extern my_bool dynstr_append_os_quoted(DYNAMIC_STRING *str, const char *append,
866866
...);
867867
extern my_bool dynstr_append_quoted(DYNAMIC_STRING *str,

mysql-test/main/mysqltest.result

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,6 @@ hej
301301
hej
302302
hej
303303
1
304-
305-
306304
a long variable content
307305
a long variable content
308306
a long a long variable content variable content

mysql-test/main/mysqltest.test

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,9 +789,6 @@ echo $1;
789789
let $1=1;
790790
let $2=$1;
791791
echo $2;
792-
let $5=$6;
793-
echo $5;
794-
echo $6;
795792

796793
let $where=a long variable content;
797794
echo $where;

0 commit comments

Comments
 (0)