diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2015-04-04 19:29:34 +0200 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2015-04-04 19:29:34 +0200 |
commit | 05b30fbcc38cdc5dcd248f9b8385a9fec65f2d96 (patch) | |
tree | 2b9b3961facc3d6edb9292a026b1418dd0a6a1cc /storage | |
parent | 836740cd8f638967ec55e4694f258a8a8642ae3b (diff) | |
download | mariadb-git-05b30fbcc38cdc5dcd248f9b8385a9fec65f2d96.tar.gz |
Fix MDEV-7890
Diffstat (limited to 'storage')
-rw-r--r-- | storage/connect/ha_connect.cc | 30 | ||||
-rw-r--r-- | storage/connect/ha_connect.h | 2 | ||||
-rw-r--r-- | storage/connect/tabmysql.cpp | 3 | ||||
-rw-r--r-- | storage/connect/xobject.cpp | 28 | ||||
-rw-r--r-- | storage/connect/xobject.h | 1 |
5 files changed, 48 insertions, 16 deletions
diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 74f89fa2abe..d310ff55980 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -2173,12 +2173,12 @@ int ha_connect::CheckRecord(PGLOBAL g, const uchar *oldbuf, uchar *newbuf) /***********************************************************************/ /* Return the where clause for remote indexed read. */ /***********************************************************************/ -bool ha_connect::MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q, +bool ha_connect::MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL op, char q, const void *key, int klen) { const uchar *ptr; uint rem, len, stlen; //, prtlen; - bool nq, b= false; + bool nq, oom, b= false; Field *fp; KEY *kfp; KEY_PART_INFO *kpart; @@ -2190,7 +2190,7 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q, return true; } // endif key - strcat(qry, " WHERE ("); + oom= qry->Append(" WHERE ("); kfp= &table->key_info[active_index]; rem= kfp->user_defined_key_parts, len= klen, @@ -2203,24 +2203,26 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q, nq= fp->str_needs_quotes(); if (b) - strcat(qry, " AND "); + oom|= qry->Append(" AND "); else b= true; - strcat(strncat(strcat(qry, q), fp->field_name, strlen(fp->field_name)), q); + oom|= qry->Append(q); + oom|= qry->Append((PSZ)fp->field_name); + oom|= qry->Append(q); switch (op) { case OP_EQ: case OP_GT: case OP_GE: - strcat(qry, GetValStr(op, false)); + oom|= qry->Append((PSZ)GetValStr(op, false)); break; default: - strcat(qry, " ??? "); + oom|= qry->Append(" ??? "); } // endwitch op if (nq) - strcat(qry, "'"); + oom|= qry->Append('\''); if (kpart->key_part_flag & HA_VAR_LENGTH_PART) { String varchar; @@ -2228,17 +2230,17 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q, varchar.set_quick((char*) ptr+HA_KEY_BLOB_LENGTH, var_length, &my_charset_bin); - strncat(qry, varchar.ptr(), varchar.length()); + oom|= qry->Append(varchar.ptr(), varchar.length()); } else { char strbuff[MAX_FIELD_WIDTH]; String str(strbuff, sizeof(strbuff), kpart->field->charset()), *res; res= fp->val_str(&str, ptr); - strncat(qry, res->ptr(), res->length()); + oom|= qry->Append(res->ptr(), res->length()); } // endif flag if (nq) - strcat(qry, "'"); + oom|= qry->Append('\''); if (stlen >= len) break; @@ -2251,8 +2253,10 @@ bool ha_connect::MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q, ptr+= stlen - MY_TEST(kpart->null_bit); } // endfor kpart - strcat(qry, ")"); - return false; + if ((oom|= qry->Append(")"))) + strcpy(g->Message, "Out of memory"); + + return oom; } // end of MakeKeyWhere diff --git a/storage/connect/ha_connect.h b/storage/connect/ha_connect.h index abe8fa079fe..c3b911710b8 100644 --- a/storage/connect/ha_connect.h +++ b/storage/connect/ha_connect.h @@ -235,7 +235,7 @@ public: int CheckRecord(PGLOBAL g, const uchar *oldbuf, uchar *newbuf); int ReadIndexed(uchar *buf, OPVAL op, const uchar* key= NULL, uint key_len= 0); - bool MakeKeyWhere(PGLOBAL g, char *qry, OPVAL op, char *q, + bool MakeKeyWhere(PGLOBAL g, PSTRG qry, OPVAL op, char q, const void *key, int klen); inline char *Strz(LEX_STRING &ls); diff --git a/storage/connect/tabmysql.cpp b/storage/connect/tabmysql.cpp index 33a4dd67d38..e4befc8bfde 100644 --- a/storage/connect/tabmysql.cpp +++ b/storage/connect/tabmysql.cpp @@ -1078,8 +1078,7 @@ bool TDBMYSQL::ReadKey(PGLOBAL g, OPVAL op, const void *key, int len) if (Myc.m_Res) Myc.FreeResult(); - To_Def->GetHandler()->MakeKeyWhere(g, Query->GetStr(), - op, "`", key, len); + To_Def->GetHandler()->MakeKeyWhere(g, Query, op, '`', key, len); if (To_CondFil) { oom = Query->Append(" AND ("); diff --git a/storage/connect/xobject.cpp b/storage/connect/xobject.cpp index 817acb561fe..92bf039c07c 100644 --- a/storage/connect/xobject.cpp +++ b/storage/connect/xobject.cpp @@ -290,6 +290,34 @@ bool STRING::Set(char *s, uint n) } // end of Set /***********************************************************************/ +/* Append a char* to a STRING. */ +/***********************************************************************/ +bool STRING::Append(const char *s, uint ln) +{ + if (!s) + return false; + + uint len = Length + ln + 1; + + if (len > Size) { + char *p = Realloc(len); + + if (!p) + return true; + else if (p != Strp) { + strcpy(p, Strp); + Strp = p; + } // endif p + + } // endif n + + strncpy(Strp + Length, s, ln); + Length = len - 1; + Strp[Length] = 0; + return false; +} // end of Append + +/***********************************************************************/ /* Append a PSZ to a STRING. */ /***********************************************************************/ bool STRING::Append(PSZ s) diff --git a/storage/connect/xobject.h b/storage/connect/xobject.h index 3660ee86918..8e2358dd526 100644 --- a/storage/connect/xobject.h +++ b/storage/connect/xobject.h @@ -134,6 +134,7 @@ class DllExport STRING : public BLOCK { inline void Reset(void) {*Strp = 0;} bool Set(PSZ s); bool Set(char *s, uint n); + bool Append(const char *s, uint ln); bool Append(PSZ s); bool Append(STRING &str); bool Append(char c); |