[flac-dev] [PATCH] Fix buffer overflow in metaflac

Erik de Castro Lopo mle+la at mega-nerd.com
Thu Apr 5 04:02:10 PDT 2012


Cristian Rodríguez wrote:

> strlen() returns the length excluding the terminating null byte..then
> an string of len 4 will be off-by-one in application_id[4];
> 
> GCC 4.7 detects this bug.

Ah nice!

> diff --git a/src/metaflac/options.c b/src/metaflac/options.c
> index eb3498d..2cb0959 100644
> --- a/src/metaflac/options.c
> +++ b/src/metaflac/options.c
> @@ -1040,7 +1040,7 @@ FLAC__bool parse_block_type(const char *in, Argument_BlockType *out)
>  			out->entries[entry].type = FLAC__METADATA_TYPE_APPLICATION;
>  			out->entries[entry].filter_application_by_id = (0 != r);
>  			if(0 != r) {
> -				if(strlen(r) == 4) {
> +				if(strlen(r) == 3) {
>  					strcpy(out->entries[entry].application_id, r);
>  				}


I actually think that this is a better solution:

                                if(strlen(r) == 4) {
-                                       strcpy(out->entries[entry].application_id, r);
+                                       memcpy(out->entries[entry].application_id, r, 4);
                                }


Cheers,
Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


More information about the flac-dev mailing list