[libvirt] [PATCH] Blank out invalid interface names with escaped letters etc.

Eric Blake eblake at redhat.com
Wed Mar 31 15:55:04 UTC 2010


On 03/31/2010 07:20 AM, Daniel P. Berrange wrote:
> There's a slightly simpler way you can do this using strspn avoiding the
> regex engine
> 
>  #define VALID_IFNAME_CHARS
>   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
> 
>  rc = strspn(ifname, VALID_IFNAME_CHARS) != strlen (value);

That scans the string twice; if ifname is arbitrarily long, this can be
inefficient.  As a micro-optimization, you could instead check:

rc = !ifname[strspn(ifname, VALID_IFNAME_CHARS)];

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 323 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100331/7910e0f2/attachment-0001.sig>


More information about the libvir-list mailing list