aboutsummaryrefslogtreecommitdiff
https://github.com/cacalabs/libcaca/commit/46b4ea7cea72d6b3ffe65d33e604b1774dcc2bbd.patch

From 46b4ea7cea72d6b3ffe65d33e604b1774dcc2bbd Mon Sep 17 00:00:00 2001
From: Sam Hocevar <sam@hocevar.net>
Date: Fri, 26 Feb 2021 10:55:38 +0100
Subject: [PATCH] canvas: fix an integer overflow in caca_resize().

Fixes: #52 (CVE-2021-3410)
---
 caca/canvas.c       | 13 +++++++++++--
 caca/codec/import.c |  1 +
 caca/codec/text.c   | 21 ++++++++++++++-------
 3 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/caca/canvas.c b/caca/canvas.c
index 3fdd37ae..d0715392 100644
--- a/caca/canvas.c
+++ b/caca/canvas.c
@@ -45,6 +45,7 @@ static int caca_resize(caca_canvas_t *, int, int);
  *
  *  If an error occurs, NULL is returned and \b errno is set accordingly:
  *  - \c EINVAL Specified width or height is invalid.
+ *  - \c EOVERFLOW Specified width and height overflowed.
  *  - \c ENOMEM Not enough memory for the requested canvas size.
  *
  *  \param width The desired canvas width
@@ -200,6 +201,7 @@ int caca_unmanage_canvas(caca_canvas_t *cv, int (*callback)(void *), void *p)
  *
  *  If an error occurs, -1 is returned and \b errno is set accordingly:
  *  - \c EINVAL Specified width or height is invalid.
+ *  - \c EOVERFLOW Specified width and height overflowed.
  *  - \c EBUSY The canvas is in use by a display driver and cannot be resized.
  *  - \c ENOMEM Not enough memory for the requested canvas size. If this
  *    happens, the canvas handle becomes invalid and should not be used.
@@ -363,7 +365,7 @@ int caca_rand(int min, int max)
 
 int caca_resize(caca_canvas_t *cv, int width, int height)
 {
-    int x, y, f, old_width, old_height, new_size, old_size;
+    int x, y, f, old_width, old_height, old_size;
 
     old_width = cv->width;
     old_height = cv->height;
@@ -375,7 +377,14 @@ int caca_resize(caca_canvas_t *cv, int width, int height)
      * dirty rectangle handling */
     cv->width = width;
     cv->height = height;
-    new_size = width * height;
+    int new_size = width * height;
+
+    /* Check for overflow */
+    if (new_size / width != height)
+    {
+        seterrno(EOVERFLOW);
+        return -1;
+    }
 
     /* If width or height is smaller (or both), we have the opportunity to
      * reduce or even remove dirty rectangles */
diff --git a/caca/codec/import.c b/caca/codec/import.c
index 8836fd08..2dafe3cf 100644
--- a/caca/codec/import.c
+++ b/caca/codec/import.c
@@ -61,6 +61,7 @@ static ssize_t import_caca(caca_canvas_t *, void const *, size_t);
  *
  *  If an error occurs, -1 is returned and \b errno is set accordingly:
  *  - \c ENOMEM Not enough memory to allocate canvas.
+ *  - \c EOVERFLOW Importing data caused a value overflow.
  *  - \c EINVAL Invalid format requested.
  *
  *  \param cv A libcaca canvas in which to import the file.
diff --git a/caca/codec/text.c b/caca/codec/text.c
index 358b7224..94a2a4d7 100644
--- a/caca/codec/text.c
+++ b/caca/codec/text.c
@@ -46,7 +46,7 @@ ssize_t _import_text(caca_canvas_t *cv, void const *data, size_t size)
     char const *text = (char const *)data;
     unsigned int width = 0, height = 0, x = 0, y = 0, i;
 
-    caca_set_canvas_size(cv, width, height);
+    caca_set_canvas_size(cv, 0, 0);
 
     for(i = 0; i < size; i++)
     {
@@ -70,15 +70,19 @@ ssize_t _import_text(caca_canvas_t *cv, void const *data, size_t size)
             if(y >= height)
                 height = y + 1;
 
-            caca_set_canvas_size(cv, width, height);
+            if (caca_set_canvas_size(cv, width, height) < 0)
+                return -1;
         }
 
         caca_put_char(cv, x, y, ch);
         x++;
     }
 
-    if(y > height)
-        caca_set_canvas_size(cv, width, height = y);
+    if (y > height)
+    {
+        if (caca_set_canvas_size(cv, width, height = y) < 0)
+            return -1;
+    }
 
     return (ssize_t)size;
 }
@@ -431,7 +435,8 @@ ssize_t _import_ansi(caca_canvas_t *cv, void const *data, size_t size, int utf8)
             {
                 savedattr = caca_get_attr(cv, -1, -1);
                 caca_set_attr(cv, im.clearattr);
-                caca_set_canvas_size(cv, width = x + wch, height);
+                if (caca_set_canvas_size(cv, width = x + wch, height) < 0)
+                    return -1;
                 caca_set_attr(cv, savedattr);
             }
             else
@@ -448,7 +453,8 @@ ssize_t _import_ansi(caca_canvas_t *cv, void const *data, size_t size, int utf8)
             caca_set_attr(cv, im.clearattr);
             if(growy)
             {
-                caca_set_canvas_size(cv, width, height = y + 1);
+                if (caca_set_canvas_size(cv, width, height = y + 1) < 0)
+                    return -1;
             }
             else
             {
@@ -480,7 +486,8 @@ ssize_t _import_ansi(caca_canvas_t *cv, void const *data, size_t size, int utf8)
     {
         savedattr = caca_get_attr(cv, -1, -1);
         caca_set_attr(cv, im.clearattr);
-        caca_set_canvas_size(cv, width, height = y);
+        if (caca_set_canvas_size(cv, width, height = y))
+            return -1;
         caca_set_attr(cv, savedattr);
     }
 
>Felix Gruber 2022-01-20gnu: dune-localfunctions: Update to 2.7.1....* gnu/packages/maths.scm (dune-localfunctions): Update to 2.7.1. [arguments]: Parallelize build-tests phase. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Felix Gruber 2022-01-20gnu: dune-istl: Update to 2.7.1....* gnu/packages/maths.scm (dune-istl): Update to 2.7.1. [arguments]: Parallelize build-tests phase. [source](patches) Remove patch that is no longer needed. * gnu/packages/patches/dune-istl-2.7-fix-non-mpi-tests.patch: Remove file. * gnu/local.mk (dist_patch_DATA): Remove above patch. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Felix Gruber 2022-01-20gnu: dune-grid: Update to 2.7.1....* gnu/packages/maths.scm (dune-grid): Update to 2.7.1. [arguments]: Parallelize build-tests phase. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Felix Gruber 2022-01-20gnu: dune-uggrid: Update to 2.7.1....* gnu/packages/maths.scm (dune-uggrid): Update to 2.7.1. [arguments]: Parallelize build-tests phase. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Felix Gruber 2022-01-20gnu: dune-geometry: Update to 2.7.1....* gnu/packages/maths.scm (dune-geometry): Update to 2.7.1. [arguments]: Parallelize build-tests phase. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Felix Gruber 2022-01-20gnu: dune-common: Update to 2.7.1....* gnu/packages/maths.scm (dune-common): Update to 2.7.1. [arguments]: Parallelize build-tests phase. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Felix Gruber 2022-01-20gnu: Modernize add-openmpi-to-dune-package...* gnu/packages/maths.scm (add-openmpi-to-dune-package): Use modify-inputs. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Felix Gruber 2022-01-12gnu: Remove python2-cvxopt....* gnu/packages/maths.scm (python2-cvxopt): Remove variable. Signed-off-by: Leo Famulari <leo@famulari.name> Felix Gruber 2022-01-12gnu: python-cvxopt: Update to 1.2.7....* gnu/packages/maths.scm (python-cvxopt): Update to 1.2.7. Signed-off-by: Leo Famulari <leo@famulari.name> Felix Gruber 2022-01-11gnu: ceres: Update to 2.0.0....* gnu/packages/maths.scm (ceres): Update to 2.0.0. [inputs]: Use simplified format. (ceres-solver-benchmarks)[phases]: Add schur_eliminator_benchmark. Replace autodiff_cost_function_benchmark with new autodiff_benchmarks. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Felix Gruber 2022-01-11gnu: dealii: Update to 9.3.2....* gnu/packages/maths.scm (dealii): Update to 9.3.2. [source]: Add dealii-fix-compiliation-with-boost-1.78.patch and dealii-fix-sundials.patch. [inputs]: Use simplified format. [native-inputs]: Use simplified format. * gnu/packages/patches/dealii-fix-compiliation-with-boost-1.78.patch: New file. * gnu/packages/patches/dealii-fix-sundials.patch: New file. * gnu/local.mk: Add new patch files. Signed-off-by: Nicolas Goaziou <mail@nicolasgoaziou.fr> Felix Gruber 2022-01-01gnu: gsl: Add 'tunable?' property....* gnu/packages/maths.scm (gsl)[properties]: New field. Ludovic Courtès 2022-01-01gnu: Add ceres-solver-benchmarks....* gnu/packages/maths.scm (ceres-solver-benchmarks): New variable. Ludovic Courtès 2022-01-01gnu: ceres-solver: Mark as tunable....* gnu/packages/maths.scm (ceres)[properties]: New field. Ludovic Courtès 2021-12-30gnu: Capitalize beginning of synopsis....* gnu/packages/admin.scm (hungrycat)[synopsis]: Captalize. * gnu/packages/cobol.scm (gnucobol)[synopsis]: Likewise. * gnu/packages/cpp.scm (clipper)[synopsis]: Likewise. * gnu/packages/crates-graphics.scm (rust-piston-texture-0.8)[synopsis]: Likewise. * gnu/packages/crates-io.scm (rust-alloc-stdlib-0.2, rust-atom-0.3, rust-oorandom-11.1, rust-r2d2, rust-scheduled-thread-pool-0.2, rust-takeable-option-0.4, rust-ttf-parser-0.12)[synopsis]: Likewise. * gnu/packages/games.scm (roguebox-adventures)[synopsis]: Likewise. * gnu/packages/gl.scm (libepoxy)[synopsis]: Likewise. * gnu/packages/gnome-xyz.scm (arc-theme)[synopsis]: Likewise. * gnu/packages/haskell-xyz.scm (ghc-cborg-json, ghc-rio)[synopsis]: Likewise. * gnu/packages/installers.scm (mingw-path)[synopsis]: Likewise. * gnu/packages/lisp-xyz.scm (sbcl-cl-utilities)[synopsis]: Likewise. * gnu/packages/maths.scm (coda)[synopsis]: Likewise. * gnu/packages/ocaml.scm (ocaml4.07-ppx-sexp-message)[synopsis]: Likewise. * gnu/packages/perl6.scm (perl6-json)[synopsis]: Likewise. * gnu/packages/python-xyz.scm (python-markuppy, python-febelfin-coda)[synopsis]: Likewise. * gnu/packages/statistics.scm (r-magrittr)[synopsis]: Likewise. * gnu/packages/terminals.scm (sakura)[synopsis]: Likewise. Vagrant Cascadian 2021-12-30gnu: Remove leading article from synopsis....* gnu/packages/admin.scm (hungrycat)[synopsis]: Remove leading article. * gnu/packages/cobol.scm (gnucobol)[synopsis]: Likewise. * gnu/packages/cpp.scm (clipper)[synopsis]: Likewise. * gnu/packages/crates-graphics.scm (rust-piston-texture-0.8)[synopsis]: Likewise. * gnu/packages/crates-io.scm (rust-alloc-stdlib-0.2, rust-atom-0.3, rust-oorandom-11.1, rust-r2d2, rust-scheduled-thread-pool-0.2, rust-takeable-option-0.4, rust-ttf-parser-0.12, rust-svd-parser-0.9)[synopsis]: Likewise. * gnu/packages/games.scm (roguebox-adventures)[synopsis]: Likewise. * gnu/packages/gl.scm (libepoxy)[synopsis]: Likewise. * gnu/packages/gnome-xyz.scm (arc-theme)[synopsis]: Likewise. * gnu/packages/haskell-xyz.scm (ghc-cborg-json, ghc-rio)[synopsis]: Likewise. * gnu/packages/installers.scm (mingw-path)[synopsis]: Likewise. * gnu/packages/lisp-xyz.scm (sbcl-cl-utilities)[synopsis]: Likewise. * gnu/packages/lisp.scm (gcl, clisp)[synopsis]: Likewise. * gnu/packages/maths.scm (coda)[synopsis]: Likewise. * gnu/packages/ocaml.scm (ocaml4.07-ppx-sexp-message)[synopsis]: Likewise. * gnu/packages/perl6.scm (perl6-json)[synopsis]: Likewise. * gnu/packages/python-xyz.scm (python-pari-jupyter, python-markuppy, python-febelfin-coda)[synopsis]: Likewise. * gnu/packages/scheme.scm (mit-scheme)[synopsis]: Likewise. * gnu/packages/statistics.scm (r-magrittr)[synopsis]: Likewise. * gnu/packages/terminals.scm (sakura)[synopsis]: Likewise. Vagrant Cascadian 2021-12-26gnu: Add feedgnuplot....* gnu/packages/maths.scm (feedgnuplot): New public variable. Marius Bakke 2021-12-22gnu: frama-c: Update to 24.0....* gnu/packages/maths.scm (frama-c): Update to 24.0. Julien Lepiller 2021-12-19gnu: cglm: Use meson-build-system....The CMake-based builds fail to correctly encode the version, leading to build failures in dependencies. See <https://bugs.gnu.org/52663>. * gnu/packages/maths.scm (cglm)[build-system]: Change to meson-build-system. [arguments]: Adjust #:configure-flags accordingly. Liliana Marie Prikler 2021-12-19gnu: cglm: Update to 0.8.4....* gnu/packages/maths.scm (cglm): Update to 0.8.4. Liliana Marie Prikler