Commit f0da39be authored by Olivier Bertrand's avatar Olivier Bertrand

- Fix MDEV-13782

  Problem with NOT LIKE queries.
  modified:   storage/connect/ha_connect.cc
  modified:   sql/item_cmpfunc.h

- Fix MDEV-21084
  Misusage of strncat could cause buffer overflow.
  modified:   storage/connect/reldef.cpp
  modified:   storage/connect/tabcmg.cpp
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabrest.cpp
  modified:   storage/connect/tabxml.cpp
parent fb91774e
...@@ -1899,7 +1899,6 @@ class Item_func_like :public Item_bool_func2 ...@@ -1899,7 +1899,6 @@ class Item_func_like :public Item_bool_func2
bool escape_used_in_parsing; bool escape_used_in_parsing;
bool use_sampling; bool use_sampling;
bool negated;
DTCollation cmp_collation; DTCollation cmp_collation;
String cmp_value1, cmp_value2; String cmp_value1, cmp_value2;
...@@ -1916,6 +1915,7 @@ class Item_func_like :public Item_bool_func2 ...@@ -1916,6 +1915,7 @@ class Item_func_like :public Item_bool_func2
Item_func::Functype type, Item *value); Item_func::Functype type, Item *value);
public: public:
int escape; int escape;
bool negated;
Item_func_like(THD *thd, Item *a, Item *b, Item *escape_arg, bool escape_used): Item_func_like(THD *thd, Item *a, Item *b, Item *escape_arg, bool escape_used):
Item_bool_func2(thd, a, b), canDoTurboBM(FALSE), pattern(0), pattern_len(0), Item_bool_func2(thd, a, b), canDoTurboBM(FALSE), pattern(0), pattern_len(0),
......
...@@ -2966,10 +2966,10 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond) ...@@ -2966,10 +2966,10 @@ PCFIL ha_connect::CheckCond(PGLOBAL g, PCFIL filp, const Item *cond)
case Item_func::LE_FUNC: vop= OP_LE; break; case Item_func::LE_FUNC: vop= OP_LE; break;
case Item_func::GE_FUNC: vop= OP_GE; break; case Item_func::GE_FUNC: vop= OP_GE; break;
case Item_func::GT_FUNC: vop= OP_GT; break; case Item_func::GT_FUNC: vop= OP_GT; break;
//case Item_func::LIKE_FUNC: case Item_func::LIKE_FUNC:
// vop = OP_LIKE; vop = OP_LIKE;
// neg= ((Item_func_like*)condf)->negated; neg= ((Item_func_like*)condf)->negated;
// break; break;
case Item_func::ISNOTNULL_FUNC: case Item_func::ISNOTNULL_FUNC:
neg= true; neg= true;
// fall through // fall through
......
...@@ -624,7 +624,8 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g) ...@@ -624,7 +624,8 @@ PTABDEF OEMDEF::GetXdef(PGLOBAL g)
return NULL; return NULL;
} else } else
// PlugSetPath(soname, Module, GetPluginDir()); // Crashes on Fedora // PlugSetPath(soname, Module, GetPluginDir()); // Crashes on Fedora
strncat(strcpy(soname, GetPluginDir()), Module, _MAX_PATH); strncat(strcpy(soname, GetPluginDir()), Module,
sizeof(soname) - strlen(soname) - 1);
#if defined(__WIN__) #if defined(__WIN__)
// Is the DLL already loaded? // Is the DLL already loaded?
......
...@@ -56,22 +56,27 @@ bool CMGDISC::FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc, ...@@ -56,22 +56,27 @@ bool CMGDISC::FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc,
char colname[65]; char colname[65];
char fmt[129]; char fmt[129];
bool newcol; bool newcol;
size_t n;
while (bson_iter_next(iter)) { while (bson_iter_next(iter)) {
key = bson_iter_key(iter); key = bson_iter_key(iter);
newcol = true; newcol = true;
if (pcn) { if (pcn) {
strncpy(colname, pcn, 64); n = sizeof(colname) - 1;
colname[64] = 0; strncpy(colname, pcn, n);
strncat(strncat(colname, "_", 65), key, 65); colname[n] = 0;
n -= strlen(colname);
strncat(strncat(colname, "_", n), key, n - 1);
} else } else
strcpy(colname, key); strcpy(colname, key);
if (pfmt) { if (pfmt) {
strncpy(fmt, pfmt, 128); n = sizeof(fmt) - 1;
fmt[128] = 0; strncpy(fmt, pfmt, n);
strncat(strncat(fmt, ".", 129), key, 129); fmt[n] = 0;
n -= strlen(fmt);
strncat(strncat(fmt, ".", n), key, n - 1);
} else } else
strcpy(fmt, key); strcpy(fmt, key);
......
...@@ -396,6 +396,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j) ...@@ -396,6 +396,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j)
{ {
char *p, *pc = colname + strlen(colname); char *p, *pc = colname + strlen(colname);
int ars; int ars;
size_t n;
PJOB job; PJOB job;
PJAR jar; PJAR jar;
...@@ -423,8 +424,10 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j) ...@@ -423,8 +424,10 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j)
PCSZ k = jrp->GetKey(); PCSZ k = jrp->GetKey();
if (*k != '$') { if (*k != '$') {
strncat(strncat(fmt, sep, 128), k, 128); n = sizeof(fmt) - strlen(fmt) -1;
strncat(strncat(colname, "_", 64), k, 64); strncat(strncat(fmt, sep, n), k, n - strlen(sep));
n = sizeof(colname) - strlen(colname) - 1;
strncat(strncat(colname, "_", n), k, n - 1);
} // endif Key } // endif Key
if (Find(g, jrp->GetVal(), k, j + 1)) if (Find(g, jrp->GetVal(), k, j + 1))
...@@ -443,19 +446,26 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j) ...@@ -443,19 +446,26 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j)
ars = MY_MIN(jar->GetSize(false), 1); ars = MY_MIN(jar->GetSize(false), 1);
for (int k = 0; k < ars; k++) { for (int k = 0; k < ars; k++) {
n = sizeof(fmt) - (strlen(fmt) + 1);
if (!tdp->Xcol || stricmp(tdp->Xcol, key)) { if (!tdp->Xcol || stricmp(tdp->Xcol, key)) {
sprintf(buf, "%d", k); sprintf(buf, "%d", k);
if (tdp->Uri) if (tdp->Uri) {
strncat(strncat(fmt, sep, 128), buf, 128); strncat(strncat(fmt, sep, n), buf, n - strlen(sep));
else } else {
strncat(strncat(strncat(fmt, "[", 128), buf, 128), "]", 128); strncat(strncat(fmt, "[", n), buf, n - 1);
strncat(fmt, "]", n - (strlen(buf) + 1));
} // endif uri
if (all) if (all) {
strncat(strncat(colname, "_", 64), buf, 64); n = sizeof(colname) - (strlen(colname) + 1);
strncat(strncat(colname, "_", n), buf, n - 1);
} // endif all
} else } else {
strncat(fmt, (tdp->Uri ? sep : "[*]"), 128); strncat(fmt, (tdp->Uri ? sep : "[*]"), n);
}
if (Find(g, jar->GetValue(k), "", j)) if (Find(g, jar->GetValue(k), "", j))
return true; return true;
......
...@@ -162,7 +162,7 @@ PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info) ...@@ -162,7 +162,7 @@ PQRYRES __stdcall ColREST(PGLOBAL g, PTOS tp, char *tab, char *db, bool info)
// We used the file name relative to recorded datapath // We used the file name relative to recorded datapath
strcat(strcat(strcat(strcpy(filename, "."), slash), db), slash); strcat(strcat(strcat(strcpy(filename, "."), slash), db), slash);
strncat(filename, fn, _MAX_PATH); strncat(filename, fn, _MAX_PATH - strlen(filename));
// Retrieve the file from the web and copy it locally // Retrieve the file from the web and copy it locally
if (http && grf(g->Message, trace(515), http, uri, filename)) { if (http && grf(g->Message, trace(515), http, uri, filename)) {
...@@ -221,7 +221,8 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff) ...@@ -221,7 +221,8 @@ bool RESTDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
// We used the file name relative to recorded datapath // We used the file name relative to recorded datapath
//PlugSetPath(filename, Fn, GetPath()); //PlugSetPath(filename, Fn, GetPath());
strncat(strcpy(filename, GetPath()), Fn, _MAX_PATH); strcpy(filename, GetPath());
strncat(filename, Fn, _MAX_PATH - strlen(filename));
// Retrieve the file from the web and copy it locally // Retrieve the file from the web and copy it locally
rc = grf(g->Message, xt, Http, Uri, filename); rc = grf(g->Message, xt, Http, Uri, filename);
......
...@@ -240,7 +240,9 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info) ...@@ -240,7 +240,9 @@ PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info)
more: more:
if (vp->atp) { if (vp->atp) {
strncpy(colname, vp->atp->GetName(g), sizeof(colname)); size_t z = sizeof(colname) - 1;
strncpy(colname, vp->atp->GetName(g), z);
colname[z] = 0;
strncat(xcol->Name, colname, XLEN(xcol->Name)); strncat(xcol->Name, colname, XLEN(xcol->Name));
switch (vp->atp->GetText(g, buf, sizeof(buf))) { switch (vp->atp->GetText(g, buf, sizeof(buf))) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment