Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59dfbb98 authored by Viresh Kumar's avatar Viresh Kumar Committed by Alex Shi
Browse files

PM / OPP: Use snprintf() instead of sprintf()



sprintf() can access memory outside of the range of the character array,
and is risky in some situations. The driver specified prop_name string
can be longer than NAME_MAX here (only an attacker will do that though)
and so blindly copying it into the character array of size NAME_MAX
isn't safe. Instead we must use snprintf() here.

Reported-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Acked-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Acked-by: default avatarStephen Boyd <sboyd@codeaurora.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
(cherry picked from commit 5ff24d601092b222340b28466e263b1c4559407e)
Signed-off-by: default avatarAlex Shi <alex.shi@linaro.org>
parent cb8acf6d
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -808,7 +808,8 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,

	/* Search for "opp-microvolt-<name>" */
	if (dev_opp->prop_name) {
		sprintf(name, "opp-microvolt-%s", dev_opp->prop_name);
		snprintf(name, sizeof(name), "opp-microvolt-%s",
			 dev_opp->prop_name);
		prop = of_find_property(opp->np, name, NULL);
	}

@@ -849,7 +850,8 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev,
	/* Search for "opp-microamp-<name>" */
	prop = NULL;
	if (dev_opp->prop_name) {
		sprintf(name, "opp-microamp-%s", dev_opp->prop_name);
		snprintf(name, sizeof(name), "opp-microamp-%s",
			 dev_opp->prop_name);
		prop = of_find_property(opp->np, name, NULL);
	}