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. --- client/mysqlshow.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'client/mysqlshow.c') diff --git a/client/mysqlshow.c b/client/mysqlshow.c index dfa1eac3673..d4085988342 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -449,7 +449,7 @@ list_dbs(MYSQL *mysql,const char *wild) MYSQL_RES *tresult = mysql_list_tables(mysql,(char*)NULL); if (mysql_affected_rows(mysql) > 0) { - sprintf(tables,"%6lu",(ulong) mysql_affected_rows(mysql)); + snprintf(tables, sizeof(tables), "%6lu",(ulong) mysql_affected_rows(mysql)); rowcount = 0; if (opt_verbose > 1) { @@ -470,13 +470,13 @@ list_dbs(MYSQL *mysql,const char *wild) } } } - sprintf(rows,"%12lu",rowcount); + snprintf(rows, sizeof(rows), "%12lu", rowcount); } } else { - sprintf(tables,"%6d",0); - sprintf(rows,"%12d",0); + snprintf(tables, sizeof(tables), "%6d" ,0); + snprintf(rows, sizeof(rows), "%12d", 0); } mysql_free_result(tresult); } @@ -594,7 +594,7 @@ list_tables(MYSQL *mysql,const char *db,const char *table) } else { - sprintf(fields,"%8u",(uint) mysql_num_fields(rresult)); + snprintf(fields, sizeof(fields), "%8u", (uint) mysql_num_fields(rresult)); mysql_free_result(rresult); if (opt_verbose > 1) @@ -610,10 +610,10 @@ list_tables(MYSQL *mysql,const char *db,const char *table) rowcount += (unsigned long) strtoull(rrow[0], (char**) 0, 10); mysql_free_result(rresult); } - sprintf(rows,"%10lu",rowcount); + snprintf(rows, sizeof(rows), "%10lu", rowcount); } else - sprintf(rows,"%10d",0); + snprintf(rows, sizeof(rows), "%10d", 0); } } } -- cgit v1.2.1