iproute2/lib
Matteo Croce 1f420318bd utils: don't match empty strings as prefixes
iproute has an utility function which checks if a string is a prefix for
another one, to allow use of abbreviated commands, e.g. 'addr' or 'a'
instead of 'address'.

This routine unfortunately considers an empty string as prefix
of any pattern, leading to undefined behaviour when an empty
argument is passed to ip:

    # ip ''
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host
           valid_lft forever preferred_lft forever

    # tc ''
    qdisc noqueue 0: dev lo root refcnt 2

    # ip address add 192.0.2.0/24 '' 198.51.100.1 dev dummy0
    # ip addr show dev dummy0
    6: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
        link/ether 02:9d:5e:e9:3f:c0 brd ff:ff:ff:ff:ff:ff
        inet 192.0.2.0/24 brd 198.51.100.1 scope global dummy0
           valid_lft forever preferred_lft forever

Rewrite matches() so it takes care of an empty input, and doesn't
scan the input strings three times: the actual implementation
does 2 strlen and a memcpy to accomplish the same task.

Signed-off-by: Matteo Croce <mcroce@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2019-07-15 13:48:48 -07:00
..
Makefile lib: Correct object file dependencies 2018-02-16 08:14:18 -08:00
bpf.c Merge branch 'iproute2-master' into next 2019-02-22 18:50:39 -08:00
color.c lib/color: make local functions static 2018-11-19 11:42:44 -08:00
coverity_model.c scrub out whitespace issues 2016-03-27 10:50:14 -07:00
exec.c netns: switch netns in the child when executing commands 2019-06-20 14:30:41 -07:00
fs.c Include bsd/string.h only in include/utils.h 2018-11-05 08:38:32 -08:00
inet_proto.c ip: add a new parameter -Numeric 2019-06-18 08:37:47 -07:00
json_print.c Merge branch 'iproute2-master' into iproute2-next 2018-12-19 12:02:17 -08:00
json_writer.c Merge branch 'iproute2-master' into iproute2-next 2018-12-19 12:02:17 -08:00
libgenl.c SPDX license identifiers 2017-11-24 12:21:35 -08:00
libnetlink.c Merge branch 'master' into next 2019-06-21 15:59:24 -07:00
ll_addr.c lib/ll_addr: whitespace and indent cleanup 2018-11-19 11:42:44 -08:00
ll_map.c lib: suppress error msg when filling the cache 2019-05-28 12:23:52 -07:00
ll_proto.c lib: add mpls_uc and mpls_mc as link layer protocol names 2019-07-10 14:06:28 -07:00
ll_types.c ip: add a new parameter -Numeric 2019-06-18 08:37:47 -07:00
mpls_ntop.c SPDX license identifiers 2017-11-24 12:21:35 -08:00
mpls_pton.c SPDX license identifiers 2017-11-24 12:21:35 -08:00
names.c tc: drop unused name_to_id function 2018-11-19 11:42:44 -08:00
namespace.c netns: make netns_{save,restore} static 2019-06-20 14:30:41 -07:00
rt_names.c ip: add a new parameter -Numeric 2019-06-18 08:37:47 -07:00
utils.c utils: don't match empty strings as prefixes 2019-07-15 13:48:48 -07:00