]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
read-mo: Check size_t overflow
authorDaiki Ueno <ueno@gnu.org>
Tue, 18 Nov 2014 03:11:22 +0000 (12:11 +0900)
committerDaiki Ueno <ueno@gnu.org>
Sun, 23 Nov 2014 02:05:29 +0000 (11:05 +0900)
* read-mo.c: Include "xsize.h".
(get_string): Use xsum3 to avoid overflow, when checking length
and offset fields.
Reported by Jakub Wilk at:
<https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=769901>.

gettext-tools/src/ChangeLog
gettext-tools/src/read-mo.c

index d392ba7d439be4a55d45bdf61a663a09c7036ad0..e250ae14494f791e61d9dbd1c8505288b2844f4b 100644 (file)
@@ -1,3 +1,11 @@
+2014-11-18  Daiki Ueno  <ueno@gnu.org>
+
+       * read-mo.c: Include "xsize.h".
+       (get_string): Use xsum3 to avoid overflow, when checking length
+       and offset fields.
+       Reported by Jakub Wilk at:
+       <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=769901>.
+
 2014-10-28  Daiki Ueno  <ueno@gnu.org>
 
        xgettext: Allow plural extraction from a single argument function
index 9e0220ce4338f492374ae1dfa67d7a87a472d8ab..c867236d85d8351d4905a5ba9f6157230af4643d 100644 (file)
@@ -38,6 +38,7 @@
 #include "message.h"
 #include "format.h"
 #include "gettext.h"
+#include "xsize.h"
 
 #define _(str) gettext (str)
 
@@ -121,8 +122,9 @@ get_string (const struct binary_mo_file *bfp, size_t offset, size_t *lengthp)
   /* See 'struct string_desc'.  */
   nls_uint32 s_length = get_uint32 (bfp, offset);
   nls_uint32 s_offset = get_uint32 (bfp, offset + 4);
+  size_t s_end = xsum3 (s_offset, s_length, 1);
 
-  if (s_offset + s_length + 1 > bfp->size)
+  if (size_overflow_p (s_end) || s_end > bfp->size)
     error (EXIT_FAILURE, 0, _("file \"%s\" is truncated"), bfp->filename);
   if (bfp->data[s_offset + s_length] != '\0')
     error (EXIT_FAILURE, 0,