diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2017-03-18 12:49:14 +0100 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2017-03-18 12:49:14 +0100 |
commit | 5de5daa74e1ff3d3b002801c22a94c556e80d942 (patch) | |
tree | 12fce2a11ab018b9cdcadd065f8d83e0a592e97d /storage/connect/tabext.cpp | |
parent | 5bc538dd8548e669480c91b7510ef914c442d1f0 (diff) | |
download | mariadb-git-5de5daa74e1ff3d3b002801c22a94c556e80d942.tar.gz |
Fix MDEV-12220: Crash when doing UPDATE or DELETE on an external
table (ODBC, JDBC, MYSQL) with a WHERE clause on an indexed column.
Also fix a bugs in TDBEXT::MakeCommand (use of uninitialised Quote)
Add in this function the eventual Schema (database) prefixing.
modified: storage/connect/connect.cc
modified: storage/connect/tabext.cpp
Typo
modified: storage/connect/tabjdbc.h
Diffstat (limited to 'storage/connect/tabext.cpp')
-rw-r--r-- | storage/connect/tabext.cpp | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/storage/connect/tabext.cpp b/storage/connect/tabext.cpp index c3403ca0081..ad9716b6a10 100644 --- a/storage/connect/tabext.cpp +++ b/storage/connect/tabext.cpp @@ -434,15 +434,16 @@ bool TDBEXT::MakeSQL(PGLOBAL g, bool cnt) /***********************************************************************/ bool TDBEXT::MakeCommand(PGLOBAL g) { - char *p, *stmt, name[68], *body = NULL; + char *p, *stmt, name[132], *body = NULL, *schmp = NULL; char *qrystr = (char*)PlugSubAlloc(g, NULL, strlen(Qrystr) + 1); bool qtd = Quoted > 0; + char q = qtd ? *Quote : ' '; int i = 0, k = 0; // Make a lower case copy of the originale query and change // back ticks to the data source identifier quoting character do { - qrystr[i] = (Qrystr[i] == '`') ? *Quote : tolower(Qrystr[i]); + qrystr[i] = (Qrystr[i] == '`') ? q : tolower(Qrystr[i]); } while (Qrystr[i++]); if (To_CondFil && (p = strstr(qrystr, " where "))) { @@ -459,27 +460,50 @@ bool TDBEXT::MakeCommand(PGLOBAL g) strlwr(strcat(strcat(strcpy(name, " "), Name), " ")); if (strstr(" update delete low_priority ignore quick from ", name)) { - strlwr(strcat(strcat(strcpy(name, Quote), Name), Quote)); - k += 2; + if (Quote) { + strlwr(strcat(strcat(strcpy(name, Quote), Name), Quote)); + k += 2; + } else { + strcpy(g->Message, "Quoted must be specified"); + return true; + } // endif Quote + } else strlwr(strcpy(name, Name)); // Not a keyword if ((p = strstr(qrystr, name))) { for (i = 0; i < p - qrystr; i++) - stmt[i] = (Qrystr[i] == '`') ? *Quote : Qrystr[i]; + stmt[i] = (Qrystr[i] == '`') ? q : Qrystr[i]; stmt[i] = 0; + k += i + (int)strlen(Name); - if (qtd && *(p - 1) == ' ') + if (Schema && *Schema) + schmp = Schema; + + if (qtd && *(p - 1) == ' ') { + if (schmp) + strcat(strcat(stmt, schmp), "."); + strcat(strcat(strcat(stmt, Quote), TableName), Quote); - else + } else { + if (schmp) { + if (qtd && *(p - 1) != ' ') { + stmt[i - 1] = 0; + strcat(strcat(strcat(stmt, schmp), "."), Quote); + } else + strcat(strcat(stmt, schmp), "."); + + } // endif schmp + strcat(stmt, TableName); + } // endif's i = (int)strlen(stmt); do { - stmt[i++] = (Qrystr[k] == '`') ? *Quote : Qrystr[k]; + stmt[i++] = (Qrystr[k] == '`') ? q : Qrystr[k]; } while (Qrystr[k++]); if (body) |