This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] locale: don't crash if locale-archive is an empty file


On 11/29/2013 10:39 AM, Aurelien Jarno wrote:
> In case of power failure followed by filesystem issues locale-archive
> can end-up containing all zeros. In that case all calls to setlocale()
> generate a SIGFPE. This renders a system with a default non-C locale
> unbootable.
> 
> Avoid this by ignoring the locale instead of generating a SIGFPE.
> ---
>  locale/loadarchive.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> 2013-11-29  Aurelien Jarno <aurelien@aurel32.net>
> 
> 	* locale/loadarchive.c (_nl_load_locale_from_archive): Avoid
> 	division by 0.
> 
> diff --git a/locale/loadarchive.c b/locale/loadarchive.c
> index 70136dc..7cfc498 100644
> --- a/locale/loadarchive.c
> +++ b/locale/loadarchive.c
> @@ -274,6 +274,10 @@ _nl_load_locale_from_archive (int category, const char **namep)
>    namehashtab = (struct namehashent *) ((char *) head
>  					+ head->namehash_offset);
>  
> +  /* Avoid division by 0 if the file is corrupted.  */
> +  if (__builtin_expect (head->namehash_size == 0, 0))
> +    goto close_and_out;
> +
>    idx = hval % head->namehash_size;
>    incr = 1 + hval % (head->namehash_size - 2);
>  
> 

How did you test this?

OK to checkin if you did a reasonable amount of testing.

e.g.

* Created locale full of zeros (at least enough zeroes to cover header).
  - Tested calling setlocale with a non-builtin locale and it fails.
  - Tested calling setlocale with a builtin locale and it works.

Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]