7c0489
commit ef21bd2d8c6805c0c186a01f7c5039189f51b8c4
7c0489
Author: DJ Delorie <dj@redhat.com>
7c0489
Date:   Fri Oct 18 17:15:52 2019 -0400
7c0489
7c0489
    loadarchive: guard against locale-archive corruption (Bug #25115)
7c0489
    
7c0489
    _nl_load_locale_from_archive() checks for a zero size, but
7c0489
    divides by both (size) and (size-2).  Extend the check to
7c0489
    guard against a size of two or less.
7c0489
    
7c0489
    Tested by manually corrupting locale-archive and running a program
7c0489
    that calls setlocale() with LOCPATH unset (size is typically very
7c0489
    large).
7c0489
    
7c0489
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
7c0489
7c0489
diff --git a/locale/loadarchive.c b/locale/loadarchive.c
7c0489
index 516d30d8d16bd578..b308fd886f44e1fd 100644
7c0489
--- a/locale/loadarchive.c
7c0489
+++ b/locale/loadarchive.c
7c0489
@@ -274,7 +274,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
7c0489
 					+ head->namehash_offset);
7c0489
 
7c0489
   /* Avoid division by 0 if the file is corrupted.  */
7c0489
-  if (__glibc_unlikely (head->namehash_size == 0))
7c0489
+  if (__glibc_unlikely (head->namehash_size <= 2))
7c0489
     goto close_and_out;
7c0489
 
7c0489
   idx = hval % head->namehash_size;