[libvirt] [PATCH] syntax-check: forbid virBufferAsprintf with string literals

Eric Blake eblake at redhat.com
Tue May 7 14:32:18 UTC 2013


On 05/07/2013 05:46 AM, Ján Tomko wrote:
> ---
>  cfg.mk | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/cfg.mk b/cfg.mk
> index 1d63bbd..06f89d1 100644
> --- a/cfg.mk
> +++ b/cfg.mk
> @@ -490,6 +490,11 @@ sc_prohibit_virBufferAdd_with_string_literal:
>  	halt='use virBufferAddLit, not virBufferAdd, with a string literal' \
>  	  $(_sc_search_regexp)
>  
> +sc_prohibit_virBufferAsprintf_with_string_literal:
> +	@prohibit='\<virBufferAsprintf *\([^,]+, *"([^%"]|\")*"\)'		\
                                                  ^^^^^^^^^^^^^
I think it's slightly tighter to write "([^%"\]|\\.|%%)*" to pick up all
backslash sequences as well as literal % in a printf format, and so that
a string that ends in a backslash ("foo\\") doesn't fail to find the
closing ".  But those are corner cases; as written you catch 99.99% of
offending code.

> +	halt='use virBufferAddLit, not virBufferAsprintf, with a string literal' \
> +	  $(_sc_search_regexp)

ACK.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

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


More information about the libvir-list mailing list