diff mbox

[block-tree] net: off by one in inet6_pton()

Message ID 20170413194231.GD591@mwanda (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter April 13, 2017, 7:42 p.m. UTC
If "scope_len" is sizeof(scope_id) then we would put the NUL terminator
one space beyond the end of the buffer.

Fixes: b1a951fe469e ("net/utils: generic inet_pton_with_scope helper")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
This one goes through Jens' tree not through net-dev.

Comments

Jens Axboe April 14, 2017, 8:09 p.m. UTC | #1
On 04/13/2017 01:42 PM, Dan Carpenter wrote:
> If "scope_len" is sizeof(scope_id) then we would put the NUL terminator
> one space beyond the end of the buffer.

Added, thanks Dan.
Sagi Grimberg April 20, 2017, 10:19 a.m. UTC | #2
Thanks Dan,

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
diff mbox

Patch

diff --git a/net/core/utils.c b/net/core/utils.c
index da1089ea5389..93066bd0305a 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -339,7 +339,7 @@  static int inet6_pton(struct net *net, const char *src, u16 port_num,
 	    src + srclen != scope_delim && *scope_delim == '%') {
 		struct net_device *dev;
 		char scope_id[16];
-		size_t scope_len = min_t(size_t, sizeof(scope_id),
+		size_t scope_len = min_t(size_t, sizeof(scope_id) - 1,
 					 src + srclen - scope_delim - 1);
 
 		memcpy(scope_id, scope_delim + 1, scope_len);