[PATCH] afs: fix a potential dead cycle and add a check for the return value of memchr()

Xiaoke Wang xkernel.wang at foxmail.com
Sun Dec 12 23:12:17 PST 2021


Note: this email is using full name
We should make the address pointed by p plus 1, otherwise, it will fall
into a dead circle. And memchr() can return NULL if the target character
is not found, so it is better to check the return value of it.

Signed-off-by: Xiaoke Wang <xkernel.wang at foxmail.com>
---
 fs/afs/addr_list.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/afs/addr_list.c b/fs/afs/addr_list.c
index de1ae0b..83e6171 100644
--- a/fs/afs/addr_list.c
+++ b/fs/afs/addr_list.c
@@ -90,8 +90,10 @@ struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *net,
 			problem = "nul";
 			goto inval;
 		}
-		if (*p == delim)
+		if (*p == delim) {
+			p++;
 			continue;
+		}
 		nr++;
 		if (*p == '[') {
 			p++;
@@ -146,6 +148,10 @@ struct afs_vlserver_list *afs_parse_text_addrs(struct afs_net *net,
 		if (*p == '[') {
 			p++;
 			q = memchr(p, ']', end - p);
+			if (!q) {
+				problem = "brace2";
+				goto bad_address;
+			}
 		} else {
 			for (q = p; q < end; q++)
 				if (*q == '+' || *q == delim)
-- 



More information about the linux-afs mailing list