Skip to content

Commit 95782e5

Browse files
committed
MDEV-37633 Connect UDF functions push empty string warning.
BsonGet_String and JsonGet_String with a NULL argument push an empty string warning which is the default contents of g->Message. In push_warning in the server, there is a Debug assertion that the string doesn't end in \n. This looks before the last null of the string, which in this case is before the buffer. This results in a UBSAN error as its a pointer overflow/underflow. Correct by adding an "Argument is NULL" as the warning message. Also corrected the JsonGet_String to error if the Value failed to allocate a buffer in its constructor.
1 parent a2ee2c7 commit 95782e5

File tree

7 files changed

+14
-2
lines changed

7 files changed

+14
-2
lines changed

storage/connect/bsonudf.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,11 @@ my_bool BJNX::ParseJpath(PGLOBAL g)
294294
if (Parsed)
295295
return false; // Already done
296296
else if (!Jpath)
297+
{
297298
// Jpath = Name;
299+
snprintf(g->Message, sizeof(g->Message), MSG(ARG_IS_NULL));
298300
return true;
301+
}
299302

300303
if (trace(1))
301304
htrc("ParseJpath %s\n", SVP(Jpath));

storage/connect/encas.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,4 @@
318318
case MSG_XPATH_CNTX_ERR: p = "Unable to create new XPath context"; break;
319319
case MSG_XPATH_EVAL_ERR: p = "Unable to evaluate xpath location '%s'"; break;
320320
case MSG_XPATH_NOT_SUPP: p = "Unsupported Xpath for column %s"; break;
321+
case MSG_ARG_IS_NULL: p = "Argument is NULL"; break;

storage/connect/engmsg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,4 @@
324324
#define MSG_XPATH_EVAL_ERR "Unable to evaluate xpath location '%s'"
325325
#define MSG_XPATH_NOT_SUPP "Unsupported Xpath for column %s"
326326
#define MSG_ZERO_DIVIDE "Zero divide in expression"
327+
#define MSG_ARG_IS_NULL "Argument is NULL"

storage/connect/jsonudf.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ my_bool JSNX::SetJpath(PGLOBAL g, char *path, my_bool jb)
9898
{
9999
// Check Value was allocated
100100
if (!Value)
101+
{
102+
snprintf(g->Message, sizeof(g->Message), MSG(NO_MEMORY));
101103
return true;
104+
}
102105

103106
Value->SetNullable(true);
104107
Jpath = path;
@@ -217,8 +220,11 @@ my_bool JSNX::ParseJpath(PGLOBAL g)
217220
if (Parsed)
218221
return false; // Already done
219222
else if (!Jpath)
223+
{
220224
// Jpath = Name;
225+
snprintf(g->Message, sizeof(g->Message), MSG(ARG_IS_NULL));
221226
return true;
227+
}
222228

223229
if (trace(1))
224230
htrc("ParseJpath %s\n", SVP(Jpath));

storage/connect/msgid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,4 @@
324324
#define MSG_FIX_OVFLW_TIMES 522
325325
#define MSG_FIX_UNFLW_ADD 523
326326
#define MSG_FIX_UNFLW_TIMES 524
327+
#define MSG_ARG_IS_NULL 525

storage/connect/mysql-test/connect/r/bson_udf.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ SELECT BsonGet_String(NULL json_, NULL);
352352
BsonGet_String(NULL json_, NULL)
353353
NULL
354354
Warnings:
355-
Warning 1105
355+
Warning 1105 Argument is NULL
356356
/* NULL WARNING */
357357
SELECT department, BsonGet_String(Bson_Make_Object(department, Bson_Array_Grp(salary) "Json_salaries"),'salaries.[+]') Sumsal FROM t3 GROUP BY department;
358358
department Sumsal

storage/connect/mysql-test/connect/r/json_udf.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ SELECT JsonGet_String(NULL json_, NULL);
346346
JsonGet_String(NULL json_, NULL)
347347
NULL
348348
Warnings:
349-
Warning 1105
349+
Warning 1105 Argument is NULL
350350
SELECT department, JsonGet_String(Json_Make_Object(department, Json_Array_Grp(salary) "Json_salaries"),'salaries.[+]') Sumsal FROM t3 GROUP BY department;
351351
department Sumsal
352352
0021 28500.000000

0 commit comments

Comments
 (0)