ee2e2732ff5ffb8fe39fd5e45e9769d5c22ff1b6
[openwrt/staging/aparcar.git] /
1 From 80aaaa8b93d860f828e2cf883f307894640765f0 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Wed, 10 Dec 2014 11:49:54 +0100
4 Subject: [PATCH] MIPS: BCM47XX: Use strnchr to avoid reading out of the buffer
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
10 Cc: Hauke Mehrtens <hauke@hauke-m.de>
11 Cc: Paul Walmsley <paul@pwsan.com>
12 Cc: linux-mips@linux-mips.org
13 Patchwork: https://patchwork.linux-mips.org/patch/8662/
14 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
15 ---
16 arch/mips/bcm47xx/nvram.c | 6 ++++--
17 1 file changed, 4 insertions(+), 2 deletions(-)
18
19 --- a/arch/mips/bcm47xx/nvram.c
20 +++ b/arch/mips/bcm47xx/nvram.c
21 @@ -175,7 +175,7 @@ static int nvram_init(void)
22 int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)
23 {
24 char *var, *value, *end, *eq;
25 - int err;
26 + int data_left, err;
27
28 if (!name)
29 return -EINVAL;
30 @@ -191,7 +191,9 @@ int bcm47xx_nvram_getenv(const char *nam
31 end = nvram_buf + sizeof(nvram_buf) - 2;
32 end[0] = end[1] = '\0';
33 for (; *var; var = value + strlen(value) + 1) {
34 - eq = strchr(var, '=');
35 + data_left = end - var;
36 +
37 + eq = strnchr(var, data_left, '=');
38 if (!eq)
39 break;
40 value = eq + 1;