]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
csplit: size_t overflow check
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 27 Apr 2021 03:04:19 +0000 (20:04 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 27 Apr 2021 06:32:45 +0000 (23:32 -0700)
* src/csplit.c (get_new_buffer): Fix unlikely size_t overflow.

src/csplit.c

index 79bd034e3f5a0d1ecb399237f08ca5819bdcceaa..f188e88940af87a7ff2bbe6e0992b4264e0e7e3e 100644 (file)
@@ -416,7 +416,8 @@ get_new_buffer (size_t min_size)
   if (alloc_size < min_size)
     {
       size_t s = min_size - alloc_size + INCR_SIZE - 1;
-      alloc_size += s - s % INCR_SIZE;
+      if (INT_ADD_WRAPV (alloc_size, s - s % INCR_SIZE, &alloc_size))
+        xalloc_die ();
     }
 
   new_buffer = create_new_buffer (alloc_size);