net: off by one in inet6_pton()
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 13 Apr 2017 19:42:31 +0000 (22:42 +0300)
committerJens Axboe <axboe@fb.com>
Fri, 14 Apr 2017 20:08:54 +0000 (14:08 -0600)
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>
Signed-off-by: Jens Axboe <axboe@fb.com>
net/core/utils.c

index f96cf527bb8fcdc67a634ea9cdf9c11213ef4de9..32c467cf52d65605ef63d63c6c5007636a7f65e5 100644 (file)
@@ -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);