From e828a14f760c49e4b58e0e9f32dad506b53f12fa Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 26 Apr 2015 14:27:22 +0200 Subject: [PATCH] Use snprintf() instead of sprintf()1 Make sure that we don't use more characters than allocated for filename string. Signed-off-by: Sebastien GODARD --- rd_stats.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rd_stats.c b/rd_stats.c index 4d866f3..c7db1e5 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -2156,7 +2156,8 @@ void read_fchost(struct stats_fchost *st_fc, int nbr) if (!strncmp(drd->d_name, "host", 4)) { - sprintf(fcstat_filename, FC_RX_FRAMES, SYSFS_FCHOST, drd->d_name); + snprintf(fcstat_filename, MAX_PF_NAME, FC_RX_FRAMES, + SYSFS_FCHOST, drd->d_name); if ((fp = fopen(fcstat_filename, "r"))) { if (fgets(line, sizeof(line), fp)) { sscanf(line, "%lx", &rx_frames); @@ -2164,7 +2165,8 @@ void read_fchost(struct stats_fchost *st_fc, int nbr) fclose(fp); } - sprintf(fcstat_filename, FC_TX_FRAMES, SYSFS_FCHOST, drd->d_name); + snprintf(fcstat_filename, MAX_PF_NAME, FC_TX_FRAMES, + SYSFS_FCHOST, drd->d_name); if ((fp = fopen(fcstat_filename, "r"))) { if (fgets(line, sizeof(line), fp)) { sscanf(line, "%lx", &tx_frames); @@ -2172,7 +2174,8 @@ void read_fchost(struct stats_fchost *st_fc, int nbr) fclose(fp); } - sprintf(fcstat_filename, FC_RX_WORDS, SYSFS_FCHOST, drd->d_name); + snprintf(fcstat_filename, MAX_PF_NAME, FC_RX_WORDS, + SYSFS_FCHOST, drd->d_name); if ((fp = fopen(fcstat_filename, "r"))) { if (fgets(line, sizeof(line), fp)) { sscanf(line, "%lx", &rx_words); @@ -2180,7 +2183,8 @@ void read_fchost(struct stats_fchost *st_fc, int nbr) fclose(fp); } - sprintf(fcstat_filename, FC_TX_WORDS, SYSFS_FCHOST, drd->d_name); + snprintf(fcstat_filename, MAX_PF_NAME, FC_TX_WORDS, + SYSFS_FCHOST, drd->d_name); if ((fp = fopen(fcstat_filename, "r"))) { if (fgets(line, sizeof(line), fp)) { sscanf(line, "%lx", &tx_words); -- 2.40.0