From 9de9f105b5cb88249acc39af73d32af337d6fd5f Mon Sep 17 00:00:00 2001 From: Mikhail Chalov Date: Wed, 28 Sep 2022 07:45:25 -0700 Subject: Use memory safe snprintf() in Connect Engine and elsewhere (#2210) Continue with similar changes as done in 19af1890 to replace sprintf(buf, ...) with snprintf(buf, sizeof(buf), ...), specifically in the "easy" cases where buf is allocated with a size known at compile time. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc. --- storage/connect/json.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'storage/connect/json.cpp') diff --git a/storage/connect/json.cpp b/storage/connect/json.cpp index 755480b1608..0786c3139e1 100644 --- a/storage/connect/json.cpp +++ b/storage/connect/json.cpp @@ -1023,13 +1023,13 @@ bool JDOC::SerializeValue(PJVAL jvp) case TYPE_DTM: return js->Escape(jvp->Strp); case TYPE_INTG: - sprintf(buf, "%d", jvp->N); + snprintf(buf, sizeof(buf), "%d", jvp->N); return js->WriteStr(buf); case TYPE_BINT: - sprintf(buf, "%lld", jvp->LLn); + snprintf(buf, sizeof(buf), "%lld", jvp->LLn); return js->WriteStr(buf); case TYPE_DBL: // dfp to limit to the default number of decimals - sprintf(buf, "%.*f", MY_MIN(jvp->Nd, dfp), jvp->F); + snprintf(buf, sizeof(buf), "%.*f", MY_MIN(jvp->Nd, dfp), jvp->F); return js->WriteStr(buf); case TYPE_NULL: return js->WriteStr("null"); -- cgit v1.2.1