2814ce28c7ec02571f6dce4e72439719da953ff3 hiram Tue Apr 16 10:09:16 2019 -0700 using needMem() instead of stack memory to expand limit of JSON strings to 500,000,000 output refs #18869 diff --git src/lib/jsonWrite.c src/lib/jsonWrite.c index 8ed3e02..5be6dc8 100644 --- src/lib/jsonWrite.c +++ src/lib/jsonWrite.c @@ -77,33 +77,34 @@ /* Print out preceding comma if necessary, and if var is non-NULL, quoted tag followed by colon. */ { jsonWriteMaybeComma(jw); if (var != NULL) dyStringPrintf(jw->dy, "\"%s\": ", var); } void jsonWriteString(struct jsonWrite *jw, char *var, char *string) /* Print out "var": "val" -- or rather, jsonStringEscape(val). * If var is NULL, print val only. If string is NULL, "var": null . */ { jsonWriteTag(jw, var); if (string) { size_t encSize = jsonStringEscapeSize(string); - char encoded[encSize]; + char *encoded = needMem(encSize); /* needMem limit is 500,000,000 */ jsonStringEscapeBuf(string, encoded, encSize); dyStringPrintf(jw->dy, "\"%s\"", encoded); + freeMem(encoded); } else dyStringAppend(jw->dy, "null"); } void jsonWriteDateFromUnix(struct jsonWrite *jw, char *var, long long unixTimeVal) /* Add "var": YYYY-MM-DDT-HH:MM:SSZ given a Unix time stamp. Var may be NULL. */ { struct dyString *dy = jw->dy; time_t timeStamp = unixTimeVal; struct tm tm; gmtime_r(&timeStamp, &tm); jsonWriteTag(jw, var); dyStringPrintf(dy, "\"%d:%02d:%02dT%02d:%02d:%02dZ\"", 1900+tm.tm_year, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);