Changeset: 64fc6c9b838a for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=64fc6c9b838a Modified Files: monetdb5/modules/mal/mal_mapi.c sql/ChangeLog.Apr2019 sql/backends/monet5/rel_bin.c sql/server/sql_scan.c sql/server/sql_scan.h Branch: Nov2019 Log Message:
Merge with Apr2019 branch. diffs (162 lines): diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c --- a/monetdb5/modules/mal/mal_mapi.c +++ b/monetdb5/modules/mal/mal_mapi.c @@ -126,6 +126,7 @@ static void generateChallenge(str buf, i struct challengedata { stream *in; stream *out; + char challenge[13]; }; static void @@ -145,6 +146,7 @@ doChallenge(void *data) #ifdef _MSC_VER srand((unsigned int) GDKusec()); #endif + memcpy(challenge, ((struct challengedata *) data)->challenge, sizeof(challenge)); GDKfree(data); if (buf == NULL) { close_stream(fdin); @@ -152,9 +154,6 @@ doChallenge(void *data) return; } - /* generate the challenge string */ - generateChallenge(challenge, 8, 12); - // send the challenge over the block stream mnstr_printf(fdout, "%s:mserver:9:%s:%s:%s:", challenge, @@ -503,6 +502,10 @@ SERVERlistenThread(SOCKET *Sock) char name[16]; snprintf(name, sizeof(name), "client%d", (int) ATOMIC_INC(&threadno)); + + /* generate the challenge string */ + generateChallenge(data->challenge, 8, 12); + if ((tid = THRcreate(doChallenge, data, MT_THR_DETACHED, name)) == 0) { mnstr_destroy(data->in); mnstr_destroy(data->out); @@ -1087,6 +1090,10 @@ SERVERclient(void *res, const Stream *In char name[16]; snprintf(name, sizeof(name), "client%d", (int) ATOMIC_INC(&threadno)); + + /* generate the challenge string */ + generateChallenge(data->challenge, 8, 12); + if ((tid = THRcreate(doChallenge, data, MT_THR_DETACHED, name)) == 0) { mnstr_destroy(data->in); mnstr_destroy(data->out); diff --git a/sql/ChangeLog.Apr2019 b/sql/ChangeLog.Apr2019 --- a/sql/ChangeLog.Apr2019 +++ b/sql/ChangeLog.Apr2019 @@ -1,3 +1,7 @@ # ChangeLog file for sql # This file is updated with Maddlog +* Wed Sep 25 2019 Sjoerd Mullender <sjo...@acm.org> +- Strings are now limited to 1GB, double-quoted tokens are limited to 2kB. + These sizes are bytes of (UTF-8 encoded) input data. + diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -566,6 +566,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l case e_convert: { /* if input is type any NULL or column of nulls, change type */ list *tps = e->r; + sql_exp *ll = (sql_exp *) e->l; sql_subtype *from = tps->h->data; sql_subtype *to = tps->h->next->data; stmt *l; @@ -573,11 +574,19 @@ exp_bin(backend *be, sql_exp *e, stmt *l if (from->type->localtype == 0) { l = stmt_atom(be, atom_general(sql->sa, to, NULL)); } else { - l = exp_bin(be, e->l, left, right, grp, ext, cnt, sel); + l = exp_bin(be, ll, left, right, grp, ext, cnt, sel); } if (!l) return NULL; - s = stmt_convert(be, l, from, to, sel); + /* if attempting to convert between strings, no conversion is needed */ + if (ll->type == e_column && EC_VARCHAR(from->type->eclass) && EC_VARCHAR(to->type->eclass)) { + sql_subtype *tpe = tail_type(l); + assert(tpe->type->localtype == TYPE_str); + tpe->digits = MAX(from->digits, to->digits); /* set the number of digits as the max between the two */ + s = l; + } else { + s = stmt_convert(be, l, from, to, sel); + } } break; case e_func: { node *en; diff --git a/sql/server/sql_scan.c b/sql/server/sql_scan.c --- a/sql/server/sql_scan.c +++ b/sql/server/sql_scan.c @@ -707,29 +707,37 @@ scanner_string(mvc *c, int quote, bool e bstream *rs = lc->rs; int cur = quote; bool escape = false; + const size_t limit = quote == '"' ? 1 << 11 : 1 << 30; lc->started = 1; while (cur != EOF) { - size_t pos = rs->pos + lc->yycur; + size_t pos = 0; + const size_t yycur = rs->pos + lc->yycur; - while (cur != EOF && (((cur = rs->buf[pos++]) & 0x80) == 0) && cur && (cur != quote || escape)) { + while (cur != EOF && pos < limit && + (((cur = rs->buf[yycur + pos++]) & 0x80) == 0) && + cur && (cur != quote || escape)) { if (escapes && cur == '\\') escape = !escape; else escape = false; } + if (pos == limit) { + (void) sql_error(c, 2, SQLSTATE(42000) "string too long"); + return LEX_ERROR; + } if (cur == EOF) break; - lc->yycur = pos - rs->pos; + lc->yycur += pos; /* check for quote escaped quote: Obscure SQL Rule */ /* TODO also handle double "" */ - if (cur == quote && rs->buf[pos] == quote) { + if (cur == quote && rs->buf[yycur + pos] == quote) { if (escapes) - rs->buf[pos - 1] = '\\'; + rs->buf[yycur + pos - 1] = '\\'; lc->yycur++; continue; } - assert(pos <= rs->len + 1); + assert(yycur + pos <= rs->len + 1); if (cur == quote && !escape) { return scanner_token(lc, STRING); } diff --git a/sql/server/sql_scan.h b/sql/server/sql_scan.h --- a/sql/server/sql_scan.h +++ b/sql/server/sql_scan.h @@ -21,12 +21,12 @@ struct scanner { stream *log; int yynext; /* next token, lr(1) isn't powerful enough for sql */ - size_t yylast; /* previous token, to detect superfluous semi-colons */ - size_t yysval; /* start of current token */ + int yylast; /* previous token, to detect superfluous semi-colons */ int yyval; /* current token */ - size_t yycur; /* next char in the queue */ + size_t yysval; /* start of current token */ + size_t yycur; /* next char in the queue */ + size_t as; /* start of query part of view's etc */ char yybak; /* sometimes it's needed to write an EOS marker */ - size_t as; /* start of query part of view's etc */ int key; /* query hash */ int started; /* found at least one token */ prot mode; /* which mode (line (1,N), blocked) */ _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list