[Mesa-dev] [PATCH] util/build-id: check dlpi_name before strstr call

Matt Turner mattst88 at gmail.com
Thu Mar 16 16:06:38 UTC 2017


On Wed, Mar 15, 2017 at 11:10 PM, Tapani Pälli <tapani.palli at intel.com> wrote:
> According to dl_iterate_phdr man page first object visited is the
> main program where dlpi_name is an empty string. This fixes segfault
> on Android when using build-id as identifier.

If Android's libc returns dlpi_name as a NULL pointer for the main
executable, I think that's a bug in their implementation.. A null
pointer is not an empty string. The empty string is "".

At the same time, there's not really an official specification for
dl_iterate_phdr as far as I know, since it's a GNU extension.

> Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
> ---
>  src/util/build_id.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/src/util/build_id.c b/src/util/build_id.c
> index c53e71d..797ea22 100644
> --- a/src/util/build_id.c
> +++ b/src/util/build_id.c
> @@ -55,6 +55,12 @@ build_id_find_nhdr_callback(struct dl_phdr_info *info, size_t size, void *data_)
>  {
>     struct callback_data *data = data_;
>
> +   /* The first object visited by callback is the main program.
> +    * For the main program, the dlpi_name field will be an empty string.
> +    */
> +   if (info->dlpi_name == NULL)
> +      return 0;

If you change the second line of the comment to simply say "Android's
libc returns a NULL pointer for the first executable" this patch gets
my

Reviewed-by: Matt Turner <mattst88 at gmail.com>

Thanks Tapani!


More information about the mesa-dev mailing list