]> granicus.if.org Git - sysstat/commitdiff
Use snprintf() instead of sprintf()1
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 26 Apr 2015 12:27:22 +0000 (14:27 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 26 Apr 2015 12:27:22 +0000 (14:27 +0200)
Make sure that we don't use more characters than allocated for filename
string.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
rd_stats.c

index 4d866f30c56d29f5af7baa084db400d3921beb08..c7db1e5bf3516648035520d4e5a4118673c9b18c 100644 (file)
@@ -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);