1
1
/*
2
- Copyright (c) 2002, 2022 , Oracle and/or its affiliates.
2
+ Copyright (c) 2002, 2023 , Oracle and/or its affiliates.
3
3
4
4
This program is free software; you can redistribute it and/or modify
5
5
it under the terms of the GNU General Public License, version 2.0,
@@ -2081,25 +2081,23 @@ static bool strnstr(const char *str, size_t length, const char *substr) {
2081
2081
2082
2082
This is only used for external language routines.
2083
2083
2084
- @param[in] chistics Routine characteristics
2085
- @param[in] sp_body Start of external language routine body.
2086
- @param[in] sp_body_len Length of routine body
2087
- @param[out] quote Buffer to put the dollar quoute in
2084
+ @param[in] chistics Routine characteristics
2085
+ @param[in] sp_body Start of external language routine body
2086
+ @param[in] sp_body_len Length of routine body
2087
+ @param[out] quote Buffer to put the dollar quote in
2088
+ @param[in] max_quote_len Max length of dollar quote (incl. null term.)
2088
2089
2089
2090
@return Length of dollar quote
2090
2091
*/
2091
2092
static size_t find_dollar_quote (const st_sp_chistics *chistics,
2092
2093
const char *sp_body, size_t sp_body_len,
2093
- char *quote) {
2094
+ char *quote, size_t max_quote_len ) {
2094
2095
// Default delimiter is $$
2095
- strcpy (quote, " $$" );
2096
+ snprintf (quote, max_quote_len , " $$" );
2096
2097
if (!strnstr (sp_body, sp_body_len, quote)) return 2 ;
2097
2098
2098
2099
// Try $language$ instead
2099
- quote[0 ] = ' $' ;
2100
- strncpy (quote + 1 , chistics->language .str , chistics->language .length );
2101
- quote[chistics->language .length + 1 ] = ' $' ;
2102
- quote[chistics->language .length + 2 ] = ' \0 ' ;
2100
+ snprintf (quote, max_quote_len, " $%s$" , chistics->language .str );
2103
2101
if (!strnstr (sp_body, sp_body_len, quote))
2104
2102
return chistics->language .length + 2 ;
2105
2103
@@ -2109,12 +2107,7 @@ static size_t find_dollar_quote(const st_sp_chistics *chistics,
2109
2107
ha_checksum chk =
2110
2108
my_checksum (i++, reinterpret_cast <const unsigned char *>(sp_body),
2111
2109
std::max ((int )sp_body_len, 20 ));
2112
- String s;
2113
- s.set_int (chk, true , &my_charset_bin);
2114
- quote[0 ] = ' $' ;
2115
- strncpy (quote + 1 , s.c_ptr (), s.length ());
2116
- quote[s.length () + 1 ] = ' $' ;
2117
- quote[s.length () + 2 ] = ' \0 ' ;
2110
+ snprintf (quote, max_quote_len, " $%u$" , chk);
2118
2111
} while (strnstr (sp_body, sp_body_len, quote));
2119
2112
return strlen (quote);
2120
2113
}
@@ -2135,10 +2128,14 @@ static bool create_string(
2135
2128
const bool is_sql = chistics->language .length == 0 ||
2136
2129
native_strcasecmp (chistics->language .str , " SQL" ) == 0 ;
2137
2130
2138
- char dollar_quote[66 ]; // Max column size is 64; add 2 for the dollar chars
2131
+ // Max column size is 64; +3 for dollar characters and null terminator
2132
+ const size_t max_quote_len = 67 ;
2133
+ char dollar_quote[max_quote_len];
2139
2134
const size_t dollar_quote_len =
2140
- is_sql ? 0 : find_dollar_quote (chistics, body, bodylen, dollar_quote);
2141
- assert (dollar_quote_len <= 66 );
2135
+ is_sql ? 0
2136
+ : find_dollar_quote (chistics, body, bodylen, dollar_quote,
2137
+ max_quote_len);
2138
+ assert (dollar_quote_len < max_quote_len);
2142
2139
2143
2140
/* Make some room to begin with */
2144
2141
if (buf->alloc (100 + dblen + 1 + namelen + paramslen + returnslen + bodylen +
0 commit comments