Skip to content

Commit

Permalink
hwmon: (ibmpowernv) Use scnprintf() for avoiding potential buffer ove…
Browse files Browse the repository at this point in the history
…rflow

Since snprintf() returns the would-be-output size instead of the
actual output size, the succeeding calls may go beyond the given
buffer limit.  Fix it by replacing with scnprintf().

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Takashi Iwai authored and Guenter Roeck committed Mar 11, 2020
1 parent 86da28e commit 6a09687
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/hwmon/ibmpowernv.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static void make_sensor_label(struct device_node *np,
u32 id;
size_t n;

n = snprintf(sdata->label, sizeof(sdata->label), "%s", label);
n = scnprintf(sdata->label, sizeof(sdata->label), "%s", label);

/*
* Core temp pretty print
Expand All @@ -199,19 +199,19 @@ static void make_sensor_label(struct device_node *np,
* The digital thermal sensors are associated
* with a core.
*/
n += snprintf(sdata->label + n,
n += scnprintf(sdata->label + n,
sizeof(sdata->label) - n, " %d",
cpuid);
else
n += snprintf(sdata->label + n,
n += scnprintf(sdata->label + n,
sizeof(sdata->label) - n, " phy%d", id);
}

/*
* Membuffer pretty print
*/
if (!of_property_read_u32(np, "ibm,chip-id", &id))
n += snprintf(sdata->label + n, sizeof(sdata->label) - n,
n += scnprintf(sdata->label + n, sizeof(sdata->label) - n,
" %d", id & 0xffff);
}

Expand Down

0 comments on commit 6a09687

Please sign in to comment.