From: Sasha Levin <sasha.levin@oracle.com>
To: john.stultz@linaro.org, cbou@mail.ru, dwmw2@infradead.org
Cc: linux-kernel@vger.kernel.org, Sasha Levin <sasha.levin@oracle.com>
Subject: [PATCH] test_power: don't access invalid memory on empty map keys
Date: Mon, 10 Nov 2014 10:13:41 -0500 [thread overview]
Message-ID: <1415632421-7577-1-git-send-email-sasha.levin@oracle.com> (raw)
When providing an empty key to map_get_value() we'd access invalid memory
because the function assumed there would at least be one character total
in the string.
Passing an empty string would access and could possibly overwrite the byte
right before the key string.
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
drivers/power/test_power.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/power/test_power.c b/drivers/power/test_power.c
index 0152f35..b47bd17 100644
--- a/drivers/power/test_power.c
+++ b/drivers/power/test_power.c
@@ -275,6 +275,8 @@ static int map_get_value(struct battery_property_map *map, const char *key,
buf[MAX_KEYLENGTH-1] = '\0';
cr = strnlen(buf, MAX_KEYLENGTH) - 1;
+ if (cr < 0)
+ return def_val;
if (buf[cr] == '\n')
buf[cr] = '\0';
--
1.7.10.4
reply other threads:[~2014-11-10 15:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415632421-7577-1-git-send-email-sasha.levin@oracle.com \
--to=sasha.levin@oracle.com \
--cc=cbou@mail.ru \
--cc=dwmw2@infradead.org \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®