@@ -379,10 +379,10 @@ static void format_rate(FILE *fp, const unsigned long long *vals,
fprintf(fp, "%8llu ", vals[i]);
if (rates[i] > mega) {
- sprintf(temp, "%uM", (unsigned int)(rates[i]/mega));
+ scnprintf(temp, sizeof(temp), "%uM", (unsigned int)(rates[i]/mega));
fprintf(fp, "%-6s ", temp);
} else if (rates[i] > kilo) {
- sprintf(temp, "%uK", (unsigned int)(rates[i]/kilo));
+ scnprintf(temp, sizeof(temp), "%uK", (unsigned int)(rates[i]/kilo));
fprintf(fp, "%-6s ", temp);
} else
fprintf(fp, "%-6u ", (unsigned int)rates[i]);
@@ -400,10 +400,10 @@ static void format_pair(FILE *fp, const unsigned long long *vals, int i, int k)
fprintf(fp, "%8llu ", vals[i]);
if (vals[k] > giga) {
- sprintf(temp, "%uM", (unsigned int)(vals[k]/mega));
+ scnprintf(temp, sizeof(temp), "%uM", (unsigned int)(vals[k]/mega));
fprintf(fp, "%-6s ", temp);
} else if (vals[k] > mega) {
- sprintf(temp, "%uK", (unsigned int)(vals[k]/kilo));
+ scnprintf(temp, sizeof(temp), "%uK", (unsigned int)(vals[k]/kilo));
fprintf(fp, "%-6s ", temp);
} else
fprintf(fp, "%-6u ", (unsigned int)vals[k]);
@@ -675,7 +675,7 @@ static void server_loop(int fd)
p.fd = fd;
p.events = p.revents = POLLIN;
- sprintf(info_source, "%d.%lu sampling_interval=%d time_const=%d",
+ scnprintf(info_source, sizeof(info_source), "%d.%lu sampling_interval=%d time_const=%d",
getpid(), (unsigned long)random(), scan_interval/1000, time_constant/1000);
load_info();
@@ -893,7 +893,7 @@ int main(int argc, char *argv[])
sun.sun_family = AF_UNIX;
sun.sun_path[0] = 0;
- sprintf(sun.sun_path+1, "ifstat%d", getuid());
+ scnprintf(sun.sun_path + 1, sizeof(sun.sun_path) - 1, "ifstat%d", getuid());
if (scan_interval > 0) {
if (time_constant == 0)
@@ -926,14 +926,14 @@ int main(int argc, char *argv[])
npatterns = argc;
if (getenv("IFSTAT_HISTORY"))
- snprintf(hist_name, sizeof(hist_name),
+ scnprintf(hist_name, sizeof(hist_name),
"%s", getenv("IFSTAT_HISTORY"));
else
if (!stats_type)
- snprintf(hist_name, sizeof(hist_name),
+ scnprintf(hist_name, sizeof(hist_name),
"%s/.ifstat.u%d", P_tmpdir, getuid());
else
- snprintf(hist_name, sizeof(hist_name),
+ scnprintf(hist_name, sizeof(hist_name),
"%s/.%s_ifstat.u%d", P_tmpdir, stats_type,
getuid());
Use scnprintf to print only valid data Signed-off-by: Denis Kirjanov <dkirjanov@suse.de> --- misc/ifstat.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)