[PATCH net-next] wireless: test sscanf return values

Subsystems: 802.11 (including cfg80211/nl80211), mac80211, the rest

STALE4258d

3 messages, 2 authors, 2015-02-27 · open the first message on its own page

[PATCH net-next] wireless: test sscanf return values

From: Joe Perches <joe@perches.com>
Date: 2015-02-27 05:43:17

At some point, it'd be good to make sscanf use __must_check
so make sure the net/ uses of sscanf use the return value.

Signed-off-by: Joe Perches <joe@perches.com>
---

Compiled, untested.

 net/mac80211/debugfs.c | 4 ++--
 net/wireless/core.c    | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index eeb0bbd..0e44be7 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -160,9 +160,9 @@ static ssize_t sta_tx_latency_stat_write(struct file *file,
 	tx_latency->n_ranges = n_ranges;
 	for (i = 0; i < n_ranges; i++) { /* setting bin ranges */
 		token = strsep(&bins, TX_LATENCY_BIN_DELIMTER_S);
-		sscanf(token, "%d", &tx_latency->ranges[i]);
 		/* bins values should be in ascending order */
-		if (prev_bin >= tx_latency->ranges[i]) {
+		if (sscanf(token, "%d", &tx_latency->ranges[i]) != 1 ||
+		    prev_bin >= tx_latency->ranges[i]) {
 			ret = -EINVAL;
 			kfree(tx_latency);
 			goto unlock;
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 3af0ecf..69a350e 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -95,8 +95,8 @@ static int cfg80211_dev_check_name(struct cfg80211_registered_device *rdev,
 	ASSERT_RTNL();
 
 	/* prohibit calling the thing phy%d when %d is not its number */
-	sscanf(newname, PHY_NAME "%d%n", &wiphy_idx, &taken);
-	if (taken == strlen(newname) && wiphy_idx != rdev->wiphy_idx) {
+	if (sscanf(newname, PHY_NAME "%d%n", &wiphy_idx, &taken) == 1 &&
+	    taken == strlen(newname) && wiphy_idx != rdev->wiphy_idx) {
 		/* count number of places needed to print wiphy_idx */
 		digits = 1;
 		while (wiphy_idx /= 10)

RE: [PATCH net-next] wireless: test sscanf return values

From: David Laight <hidden>
Date: 2015-02-27 10:36:11

From: Joe Perches
At some point, it'd be good to make sscanf use __must_check
so make sure the net/ uses of sscanf use the return value.
Isn't it much safer to avoid sscanf() completely and use
a different function for converting numerics?

	David

Re: [PATCH net-next] wireless: test sscanf return values

From: Joe Perches <joe@perches.com>
Date: 2015-02-27 12:36:24

On Fri, 2015-02-27 at 10:35 +0000, David Laight wrote:
From: Joe Perches
quoted
At some point, it'd be good to make sscanf use __must_check
so make sure the net/ uses of sscanf use the return value.
Isn't it much safer to avoid sscanf() completely and use
a different function for converting numerics?
It's generally better to use something other than sscanf.
That doesn't mean sscanf isn't useful.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help