mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
- Fix MDEV-13925: Actually this fixes SELECT queries when
the WHERE clause have single quote. modified: storage/connect/ha_connect.cc - Use Windows VirtualAlloc and VirtualFree for the Sarea workspace modified: storage/connect/global.h modified: storage/connect/ha_connect.cc modified: storage/connect/jsonudf.cpp modified: storage/connect/plgdbutl.cpp modified: storage/connect/plugutil.cpp modified: storage/connect/user_connect.cc
This commit is contained in:
@@ -217,7 +217,8 @@ DllExport int PlugExit(PGLOBAL); // Plug global termination
|
||||
DllExport LPSTR PlugRemoveType(LPSTR, LPCSTR);
|
||||
DllExport LPCSTR PlugSetPath(LPSTR to, LPCSTR prefix, LPCSTR name, LPCSTR dir);
|
||||
DllExport BOOL PlugIsAbsolutePath(LPCSTR path);
|
||||
DllExport void *PlugAllocMem(PGLOBAL, uint);
|
||||
DllExport bool AllocSarea(PGLOBAL, uint);
|
||||
DllExport void FreeSarea(PGLOBAL);
|
||||
DllExport BOOL PlugSubSet(PGLOBAL, void *, uint);
|
||||
DllExport void *PlugSubAlloc(PGLOBAL, void *, size_t);
|
||||
DllExport char *PlugDup(PGLOBAL g, const char *str);
|
||||
|
@@ -3009,7 +3009,9 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
|
||||
return NULL;
|
||||
|
||||
if (!x) {
|
||||
const char *p;
|
||||
char *s = (ishav) ? havg : body;
|
||||
uint j, k, n;
|
||||
|
||||
// Append the value to the filter
|
||||
switch (args[i]->field_type()) {
|
||||
@@ -3065,15 +3067,37 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
|
||||
strcat(s, "'}");
|
||||
break;
|
||||
default:
|
||||
strcat(s, "'");
|
||||
strncat(s, res->ptr(), res->length());
|
||||
strcat(s, "'");
|
||||
j = strlen(s);
|
||||
s[j++] = '\'';
|
||||
p = res->ptr();
|
||||
n = res->length();
|
||||
|
||||
for (k = 0; k < n; k++) {
|
||||
if (p[k] == '\'')
|
||||
s[j++] = '\'';
|
||||
|
||||
s[j++] = p[k];
|
||||
} // endfor k
|
||||
|
||||
s[j++] = '\'';
|
||||
s[j] = 0;
|
||||
} // endswitch field type
|
||||
|
||||
} else {
|
||||
strcat(s, "'");
|
||||
strncat(s, res->ptr(), res->length());
|
||||
strcat(s, "'");
|
||||
j = strlen(s);
|
||||
s[j++] = '\'';
|
||||
p = res->ptr();
|
||||
n = res->length();
|
||||
|
||||
for (k = 0; k < n; k++) {
|
||||
if (p[k] == '\'')
|
||||
s[j++] = '\'';
|
||||
|
||||
s[j++] = p[k];
|
||||
} // endfor k
|
||||
|
||||
s[j++] = '\'';
|
||||
s[j] = 0;
|
||||
} // endif tty
|
||||
|
||||
break;
|
||||
|
@@ -1505,23 +1505,16 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n,
|
||||
ml += g->More;
|
||||
|
||||
if (ml > g->Sarea_Size) {
|
||||
#if !defined(DEVELOPMENT)
|
||||
if (trace)
|
||||
#endif
|
||||
htrc("Freeing Sarea at %p size=%d\n", g->Sarea, g->Sarea_Size);
|
||||
FreeSarea(g);
|
||||
|
||||
free(g->Sarea);
|
||||
|
||||
if (!(g->Sarea = PlugAllocMem(g, ml))) {
|
||||
if (AllocSarea(g, ml)) {
|
||||
char errmsg[MAX_STR];
|
||||
|
||||
sprintf(errmsg, MSG(WORK_AREA), g->Message);
|
||||
strcpy(g->Message, errmsg);
|
||||
g->Sarea_Size = 0;
|
||||
return true;
|
||||
} // endif Alloc
|
||||
} // endif SareaAlloc
|
||||
|
||||
g->Sarea_Size = ml;
|
||||
g->Createas = 0;
|
||||
g->Xchk = NULL;
|
||||
initid->max_length = rl;
|
||||
|
@@ -334,7 +334,7 @@ PDBUSER PlgMakeUser(PGLOBAL g)
|
||||
{
|
||||
PDBUSER dbuserp;
|
||||
|
||||
if (!(dbuserp = (PDBUSER)PlugAllocMem(g, (uint)sizeof(DBUSERBLK)))) {
|
||||
if (!(dbuserp = (PDBUSER)malloc(sizeof(DBUSERBLK)))) {
|
||||
sprintf(g->Message, MSG(MALLOC_ERROR), "PlgMakeUser");
|
||||
return NULL;
|
||||
} // endif dbuserp
|
||||
|
@@ -160,13 +160,11 @@ PGLOBAL PlugInit(LPCSTR Language, uint worksize)
|
||||
/*******************************************************************/
|
||||
/* Allocate the main work segment. */
|
||||
/*******************************************************************/
|
||||
if (worksize && !(g->Sarea = PlugAllocMem(g, worksize))) {
|
||||
if (worksize && AllocSarea(g, worksize)) {
|
||||
char errmsg[MAX_STR];
|
||||
sprintf(errmsg, MSG(WORK_AREA), g->Message);
|
||||
strcpy(g->Message, errmsg);
|
||||
g->Sarea_Size = 0;
|
||||
} else
|
||||
g->Sarea_Size = worksize;
|
||||
} // endif Sarea
|
||||
|
||||
g->jump_level = -1; /* New setting to allow recursive call of Plug */
|
||||
return(g);
|
||||
@@ -183,15 +181,7 @@ int PlugExit(PGLOBAL g)
|
||||
if (dup)
|
||||
free(dup);
|
||||
|
||||
if (g->Sarea) {
|
||||
#if !defined(DEVELOPMENT)
|
||||
if (trace)
|
||||
#endif
|
||||
htrc("Freeing Sarea at %p size=%d\n", g->Sarea, g->Sarea_Size);
|
||||
|
||||
free(g->Sarea);
|
||||
} // endif Sarea
|
||||
|
||||
FreeSarea(g);
|
||||
delete g;
|
||||
} // endif g
|
||||
|
||||
@@ -459,30 +449,65 @@ short GetLineLength(PGLOBAL g)
|
||||
/***********************************************************************/
|
||||
/* Program for memory allocation of work and language areas. */
|
||||
/***********************************************************************/
|
||||
void *PlugAllocMem(PGLOBAL g, uint size)
|
||||
bool AllocSarea(PGLOBAL g, uint size)
|
||||
{
|
||||
void *areap; /* Pointer to allocated area */
|
||||
|
||||
/*********************************************************************/
|
||||
/* This is the allocation routine for the WIN32/UNIX/AIX version. */
|
||||
/*********************************************************************/
|
||||
if (!(areap = malloc(size)))
|
||||
#if defined(__WIN__)
|
||||
if (size >= 1048576) // 1M
|
||||
g->Sarea = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
else
|
||||
#endif
|
||||
g->Sarea = malloc(size);
|
||||
|
||||
if (!g->Sarea) {
|
||||
sprintf(g->Message, MSG(MALLOC_ERROR), "malloc");
|
||||
g->Sarea_Size = 0;
|
||||
} else
|
||||
g->Sarea_Size = size;
|
||||
|
||||
#if defined(DEVELOPMENT)
|
||||
if (true) {
|
||||
#else
|
||||
if (trace) {
|
||||
#endif
|
||||
if (areap)
|
||||
htrc("Memory of %u allocated at %p\n", size, areap);
|
||||
if (g->Sarea)
|
||||
htrc("Work area of %u allocated at %p\n", size, g->Sarea);
|
||||
else
|
||||
htrc("PlugAllocMem: %s\n", g->Message);
|
||||
htrc("SareaAlloc: %s\n", g->Message);
|
||||
|
||||
} // endif trace
|
||||
|
||||
return (areap);
|
||||
} // end of PlugAllocMem
|
||||
return (!g->Sarea);
|
||||
} // end of AllocSarea
|
||||
|
||||
/***********************************************************************/
|
||||
/* Program for memory freeing the work area. */
|
||||
/***********************************************************************/
|
||||
void FreeSarea(PGLOBAL g)
|
||||
{
|
||||
if (g->Sarea) {
|
||||
#if defined(__WIN__)
|
||||
if (g->Sarea_Size >= 1048576) // 1M
|
||||
VirtualFree(g->Sarea, 0, MEM_RELEASE);
|
||||
else
|
||||
#endif
|
||||
free(g->Sarea);
|
||||
|
||||
#if defined(DEVELOPMENT)
|
||||
if (true)
|
||||
#else
|
||||
if (trace)
|
||||
#endif
|
||||
htrc("Freeing Sarea at %p size = %d\n", g->Sarea, g->Sarea_Size);
|
||||
|
||||
g->Sarea = NULL;
|
||||
g->Sarea_Size = 0;
|
||||
} // endif Sarea
|
||||
|
||||
return;
|
||||
} // end of FreeSarea
|
||||
|
||||
/***********************************************************************/
|
||||
/* Program for SubSet initialization of memory pools. */
|
||||
|
@@ -156,27 +156,18 @@ void user_connect::SetHandler(ha_connect *hc)
|
||||
bool user_connect::CheckCleanup(bool force)
|
||||
{
|
||||
if (thdp->query_id > last_query_id || force) {
|
||||
uint worksize= GetWorkSize();
|
||||
uint worksize= GetWorkSize(), size = g->Sarea_Size;
|
||||
|
||||
PlugCleanup(g, true);
|
||||
|
||||
if (g->Sarea_Size != worksize) {
|
||||
if (g->Sarea) {
|
||||
#if !defined(DEVELOPMENT)
|
||||
if (trace)
|
||||
#endif
|
||||
htrc("CheckCleanup: Free Sarea at %p size=%d\n",
|
||||
g->Sarea, g->Sarea_Size);
|
||||
|
||||
free(g->Sarea);
|
||||
} // endif Size
|
||||
if (size != worksize) {
|
||||
FreeSarea(g);
|
||||
|
||||
// Check whether the work area could be allocated
|
||||
if (!(g->Sarea = PlugAllocMem(g, worksize))) {
|
||||
g->Sarea = PlugAllocMem(g, g->Sarea_Size);
|
||||
if (AllocSarea(g, worksize)) {
|
||||
AllocSarea(g, size);
|
||||
SetWorkSize(g->Sarea_Size); // Was too big
|
||||
} else
|
||||
g->Sarea_Size = worksize; // Ok
|
||||
} // endif sarea
|
||||
|
||||
} // endif worksize
|
||||
|
||||
|
Reference in New Issue
Block a user