summaryrefslogtreecommitdiff
path: root/storage/connect/json.cpp
diff options
context:
space:
mode:
authorOlivier Bertrand <bertrandop@gmail.com>2015-12-08 16:39:13 +0100
committerOlivier Bertrand <bertrandop@gmail.com>2015-12-08 16:39:13 +0100
commit8ba013a258cb3381105354194811868683e218f3 (patch)
treeb66bf670aa700c69c5890a04489722fd1e936e86 /storage/connect/json.cpp
parentd059dd736867f5260c7e1663ea09835055b556e0 (diff)
downloadmariadb-git-8ba013a258cb3381105354194811868683e218f3.tar.gz
- Serialize: Protect again eventual longjmp's.
Always return NULL on error. Adding also the file length. modified: storage/connect/json.cpp modified: storage/connect/jsonudf.cpp - JSONCOL::WriteColumn Add types SHORT and BIGINT as accepted modified: storage/connect/tabjson.cpp - TDBJSN: Make this type use a separate storage for Json parsing and retrieve this memory between each rows. This is necessary to be able to handle big tables. See MDEV-9228. modified: storage/connect/tabjson.cpp modified: storage/connect/tabjson.h
Diffstat (limited to 'storage/connect/json.cpp')
-rw-r--r--storage/connect/json.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/storage/connect/json.cpp b/storage/connect/json.cpp
index 638999540bb..fc7edb84c0f 100644
--- a/storage/connect/json.cpp
+++ b/storage/connect/json.cpp
@@ -534,15 +534,27 @@ PVAL ParseNumeric(PGLOBAL g, int& i, STRG& src)
/***********************************************************************/
PSZ Serialize(PGLOBAL g, PJSON jsp, char *fn, int pretty)
{
+ PSZ str = NULL;
bool b = false, err = true;
JOUT *jp;
FILE *fs = NULL;
g->Message[0] = 0;
- if (!jsp) {
+ // Save stack and allocation environment and prepare error return
+ if (g->jump_level == MAX_JUMP) {
+ strcpy(g->Message, MSG(TOO_MANY_JUMPS));
+ return NULL;
+ } // endif jump_level
+
+ if (setjmp(g->jumper[++g->jump_level])) {
+ str = NULL;
+ goto fin;
+ } // endif jmp
+
+ if (!jsp) {
strcpy(g->Message, "Null json tree");
- return NULL;
+ goto fin;
} else if (!fn) {
// Serialize to a string
jp = new(g) JOUTSTR(g);
@@ -552,7 +564,7 @@ PSZ Serialize(PGLOBAL g, PJSON jsp, char *fn, int pretty)
sprintf(g->Message, MSG(OPEN_MODE_ERROR),
"w", (int)errno, fn);
strcat(strcat(g->Message, ": "), strerror(errno));
- return g->Message;
+ goto fin;;
} else if (pretty >= 2) {
// Serialize to a pretty file
jp = new(g)JOUTPRT(g, fs);
@@ -582,20 +594,20 @@ PSZ Serialize(PGLOBAL g, PJSON jsp, char *fn, int pretty)
if (fs) {
fputs(EL, fs);
fclose(fs);
- return (err) ? g->Message : NULL;
+ str = (err) ? NULL : "Ok";
} else if (!err) {
- PSZ str = ((JOUTSTR*)jp)->Strp;
-
+ str = ((JOUTSTR*)jp)->Strp;
jp->WriteChr('\0');
PlugSubAlloc(g, NULL, ((JOUTSTR*)jp)->N);
- return str;
} else {
if (!g->Message[0])
strcpy(g->Message, "Error in Serialize");
- return NULL;
} // endif's
+fin:
+ g->jump_level--;
+ return str;
} // end of Serialize
/***********************************************************************/