gallium/hud: prevent buffer overflow
authorEric Engestrom <eric.engestrom@intel.com>
Tue, 19 Mar 2019 14:11:48 +0000 (14:11 +0000)
committerEric Engestrom <eric@engestrom.ch>
Thu, 4 Apr 2019 13:59:24 +0000 (13:59 +0000)
Signed-off-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/hud/hud_diskstat.c
src/gallium/auxiliary/hud/hud_nic.c
src/gallium/auxiliary/hud/hud_sensors_temp.c

index 6860567a26ec12b407616389785fb33d25e93db4..23b98c1fa86a69b1465913add59f15e13ccaef0f 100644 (file)
@@ -213,7 +213,7 @@ add_object_part(const char *basename, const char *name, int objmode)
 {
    struct diskstat_info *dsi = CALLOC_STRUCT(diskstat_info);
 
-   strcpy(dsi->name, name);
+   snprintf(dsi->name, sizeof(dsi->name), "%s", name);
    snprintf(dsi->sysfs_filename, sizeof(dsi->sysfs_filename), "%s/%s/stat",
       basename, name);
    dsi->mode = objmode;
@@ -226,7 +226,7 @@ add_object(const char *basename, const char *name, int objmode)
 {
    struct diskstat_info *dsi = CALLOC_STRUCT(diskstat_info);
 
-   strcpy(dsi->name, name);
+   snprintf(dsi->name, sizeof(dsi->name), "%s", name);
    snprintf(dsi->sysfs_filename, sizeof(dsi->sysfs_filename), "%s/stat",
       basename);
    dsi->mode = objmode;
index 5fab3319db2862a062f0a2e28ec84c8e0edcb5af..a294602b29ec5a2342da0896c4c0b30376ff9db7 100644 (file)
@@ -114,7 +114,7 @@ query_wifi_bitrate(const struct nic_info *nic, uint64_t *bitrate)
    memset(&stats, 0, sizeof(stats));
    memset(&req, 0, sizeof(req));
 
-   strcpy(req.ifr_name, nic->name);
+   snprintf(req.ifr_name, sizeof(req.ifr_name), "%s", nic->name);
    req.u.data.pointer = &stats;
    req.u.data.flags = 1;
    req.u.data.length = sizeof(struct iw_statistics);
@@ -145,7 +145,7 @@ query_nic_rssi(const struct nic_info *nic, uint64_t *leveldBm)
    memset(&stats, 0, sizeof(stats));
    memset(&req, 0, sizeof(req));
 
-   strcpy(req.ifr_name, nic->name);
+   snprintf(req.ifr_name, sizeof(req.ifr_name), "%s", nic->name);
    req.u.data.pointer = &stats;
    req.u.data.flags = 1;
    req.u.data.length = sizeof(struct iw_statistics);
index c226e89cc42f607f5e70e12629020524e108bb24..fe80cabf82fb953af548f2b5e5c8360b3913a2cc 100644 (file)
@@ -259,8 +259,8 @@ create_object(const char *chipname, const char *featurename,
    sti->mode = mode;
    sti->chip = (sensors_chip_name *) chip;
    sti->feature = feature;
-   strcpy(sti->chipname, chipname);
-   strcpy(sti->featurename, featurename);
+   snprintf(sti->chipname, sizeof(sti->chipname), "%s", chipname);
+   snprintf(sti->featurename, sizeof(sti->featurename), "%s", featurename);
    snprintf(sti->name, sizeof(sti->name), "%s.%s", sti->chipname,
       sti->featurename);