]> git.baikalelectronics.ru Git - kernel.git/commit
tcp: warn if offset reach the maxlen limit when using snprintf
authorHangbin Liu <liuhangbin@gmail.com>
Wed, 20 Nov 2019 08:38:08 +0000 (16:38 +0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 21 Nov 2019 06:23:36 +0000 (22:23 -0800)
commit78f24b1f6ee377efb5596c3f248cdbcc4435b697
tree74a2d5c284838dca140388d71a7f226057aa9b36
parent01e4d2c2dc5f03c73be4e9727623d2b5469e62da
tcp: warn if offset reach the maxlen limit when using snprintf

snprintf returns the number of chars that would be written, not number
of chars that were actually written. As such, 'offs' may get larger than
'tbl.maxlen', causing the 'tbl.maxlen - offs' being < 0, and since the
parameter is size_t, it would overflow.

Since using scnprintf may hide the limit error, while the buffer is still
enough now, let's just add a WARN_ON_ONCE in case it reach the limit
in future.

v2: Use WARN_ON_ONCE as Jiri and Eric suggested.

Suggested-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/sysctl_net_ipv4.c
net/ipv4/tcp_cong.c
net/ipv4/tcp_ulp.c