CVE-2021-46225 (published 2022-01-12T20:15Z)

A buffer overflow in the GmfOpenMesh() function of libMeshb v7.61 allows attackers to cause a Denial of Service (DoS) via a crafted MESH file.

Severity: MEDIUM
CVSS v2 base score: 4.3 (AV:N/AC:M/Au:N/C:N/I:N/A:P)
CVSS v3 base score: 6.5, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H)

Weakness information:
cwe_id: CWE-120
cwe_name: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
description: The product copies an input buffer to an output buffer without verifying that the size of the input buffer is less than the size of the output buffer, leading to a buffer overflow.
extended_description: A buffer overflow condition exists when a product attempts to put more data in a buffer than it can hold, or when it attempts to put data in a memory area outside of the boundaries of a buffer. The simplest type of error, and the most common cause of buffer overflows, is the "classic" case in which the product copies the buffer without restricting how much is copied. Other variants exist, but the existence of a classic overflow strongly suggests that the programmer is not considering even the most basic of security protections.
         

Fix information:
repo_url: https://github.com/LoicMarechal/libMeshb
commit_details: repo_url: https://github.com/LoicMarechal/libMeshb
author: Loïc Maréchal
author_date: 2022-01-07 14:25:30+01:00
msg: Removed a potential buffer overflow crash in GmfOpenMesh and debugged the test_libmeshb_block_pipeline.f that crashed
repository: repo_url: https://github.com/LoicMarechal/libMeshb
repo_name: LoicMarechal/libMeshb
description: A library to handle the *.meshb file format.
repo_language: C
owner: LoicMarechal
file_changes: filename: test_libmeshb_block_pipeline.f
change_type: ModificationType.MODIFY
diff: @@ -1,5 +1,5 @@
 
-c     libmeshb example : transform a quadrilateral mesh into a triangular one
+c     libmeshb example: transform a quadrilateral mesh into a triangular one
 c     using fast block transfer and pipelined post processing
 
       include 'libmeshb7.ins'
@@ -39,14 +39,15 @@ c     Check memory bounds
 
 c     Read the vertices
       res = gmfgetblock(InpMsh, GmfVertices, 1_8, NmbVer,
-     +                  movver, 1, VerTab,
+     +                  0, %val(0), movver, 1, VerTab,
      +                  GmfDouble, VerTab(1,1), VerTab(1,2),
      +                  GmfDouble, VerTab(2,1), VerTab(2,2),
      +                  GmfDouble, VerTab(3,1), VerTab(3,2),
      +                  GmfInt,    RefTab(1),   RefTab(2))
 
 c     Read the quads
-      res = gmfgetblock(InpMsh, GmfQuadrilaterals, 1_8, NmbQad,0,
+      res = gmfgetblock(InpMsh, GmfQuadrilaterals, 1_8, NmbQad,
+     +                  0, %val(0), %val(0),
      +                  GmfInt, QadTab(1,1), QadTab(1,2),
      +                  GmfInt, QadTab(2,1), QadTab(2,2),
      +                  GmfInt, QadTab(3,1), QadTab(3,2),
@@ -79,7 +80,7 @@ c     Then write them down
 c     Write the triangles
       res = gmfsetkwd(OutMsh, GmfTriangles, 2*NmbQad, 0, 0)
       res = gmfsetblock(OutMsh, GmfTriangles, 1_8, 2*NmbQad,
-     +                  0,%val(0),%val(0),
+     +                  0,%val(0),
      +                  qad2tri, 2, QadTab, TriTab,
      +                  GmfInt, TriTab(1,1), TriTab(1,2),
      +                  GmfInt, TriTab(2,1), TriTab(2,2),

programming_language: Haskell
filename: libmeshb7.c
change_type: ModificationType.MODIFY
diff: @@ -2,14 +2,14 @@
 
 /*----------------------------------------------------------------------------*/
 /*                                                                            */
-/*                               LIBMESHB V7.61                               */
+/*                               LIBMESHB V7.62                               */
 /*                                                                            */
 /*----------------------------------------------------------------------------*/
 /*                                                                            */
 /*   Description:        handles .meshb file format I/O                       */
 /*   Author:             Loic MARECHAL                                        */
 /*   Creation date:      dec 09 1999                                          */
-/*   Last modification:  sep 27 2021                                          */
+/*   Last modification:  jan 07 2022                                          */
 /*                                                                            */
 /*----------------------------------------------------------------------------*/
 
@@ -655,7 +655,7 @@ int64_t GmfOpenMesh(const char *FilNam, int mod, ...)
 
          do
          {
-            res = fscanf(msh->hdl, "%s", str);
+            res = fscanf(msh->hdl, "%100s", str);
          }while( (res != EOF) && strcmp(str, "MeshVersionFormatted") );
 
          if(res == EOF)
@@ -668,7 +668,7 @@ int64_t GmfOpenMesh(const char *FilNam, int mod, ...)
 
          do
          {
-            res = fscanf(msh->hdl, "%s", str);
+            res = fscanf(msh->hdl, "%100s", str);
          }while( (res != EOF) && strcmp(str, "Dimension") );
 
          if(res == EOF)
@@ -2539,7 +2539,7 @@ static int ScaKwdTab(GmfMshSct *msh)
    if(msh->typ & Asc)
    {
       // Scan each string in the file until the end
-      while(fscanf(msh->hdl, "%s", str) != EOF)
+      while(fscanf(msh->hdl, "%100s", str) != EOF)
       {
          // Fast test in order to reject quickly the numeric values
          if(isalpha(str[0]))

programming_language: C