mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
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.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user