Menu

#897 attempt to reference unallocated memory

GC 3.2
duplicate
Chuck H.
3
2023-07-08
2023-07-07
meerkut
No
cobc -V
cobc (GnuCOBOL) 3.1.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
Built     Jun 16 2023 04:35:55
Packaged  Dec 23 2020 12:04:58 UTC
C version "10.2.1 20210110"

Source:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. L0-A.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       PROCEDURE DIVISION.
       MAIN.
           CALL "L0-D".
           STOP RUN.
      *--====================--*    
       IDENTIFICATION DIVISION.
       PROGRAM-ID. L0-B.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77  ss PIC X(10).
       PROCEDURE DIVISION.
       MAIN.
           DISPLAY "--> L0-B".
           DISPLAY ss.
           DISPLAY ss.
       END PROGRAM L0-B.
      *--====================--*
       IDENTIFICATION DIVISION.
       PROGRAM-ID. L0-C.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77  ss PIC X(10).
       PROCEDURE DIVISION.
       MAIN.
           DISPLAY "--> L0-C".
           DISPLAY ss.
       END PROGRAM L0-C.
      *--====================--*
       IDENTIFICATION DIVISION.
       PROGRAM-ID. L0-D.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       78  maxLen VALUE 80.   
       PROCEDURE DIVISION.
       MAIN.
           DISPLAY "--> L0-D".
           SET 80 TO maxLen.
       END PROGRAM L0-D.
       END PROGRAM L0-A.

Output:

cobc -x -o "test" "test.cob"

attempt to reference unallocated memory (signal SIGSEGV)

cobc: aborting compile of test.cob at line 41 (PROGRAM-ID: L0-D)
cobc: Please report this!

where line 41 is:

           SET 80 TO maxLen.

Best regards

Discussion

  • Vincent (Bryan) Coen

    You have the END PROGRAM statement incorrectly placed.
    Move all END PROGRAM to the end in reversed order ie D, then C then B and A.
    Retry

     
  • Chuck H.

    Chuck H. - 2023-07-07
    • status: open --> closed
    • assigned_to: Chuck H.
     
  • Chuck H.

    Chuck H. - 2023-07-07

    here is my output... Note that this was using the latest build of GNUCOBOL at commit R5112.

    F:\AA-minGW32-static>cobc -x bug897.cbl
    bug897.cbl: in paragraph 'MAIN':
    bug897.cbl:41: error: invalid SET statement
       39 |        MAIN.
       40 |            DISPLAY "--> L0-D".
       41 >            SET 80 TO maxLen.
       42 |        END PROGRAM L0-D.
       43 |        END PROGRAM L0-A.
    
    F:\AA-minGW32-static>
    

    After making the coding fix to the L0-D program it compiled and executed successfully

           IDENTIFICATION DIVISION.
           PROGRAM-ID. L0-A.
           DATA DIVISION.
           WORKING-STORAGE SECTION.
           PROCEDURE DIVISION.
           MAIN.
               CALL "L0-D".
               STOP RUN.
          *--====================--*
           IDENTIFICATION DIVISION.
           PROGRAM-ID. L0-B.
           DATA DIVISION.
           WORKING-STORAGE SECTION.
           77  ss PIC X(10).
           PROCEDURE DIVISION.
           MAIN.
               DISPLAY "--> L0-B".
               DISPLAY ss.
               DISPLAY ss.
           END PROGRAM L0-B.
          *--====================--*
           IDENTIFICATION DIVISION.
           PROGRAM-ID. L0-C.
           DATA DIVISION.
           WORKING-STORAGE SECTION.
           77  ss PIC X(10).
           PROCEDURE DIVISION.
           MAIN.
               DISPLAY "--> L0-C".
               DISPLAY ss.
           END PROGRAM L0-C.
          *--====================--*
           IDENTIFICATION DIVISION.
           PROGRAM-ID. L0-D.
           DATA DIVISION.
           WORKING-STORAGE SECTION.
           77  maxLen BINARY-LONG VALUE 80.
           PROCEDURE DIVISION.
           MAIN.
               DISPLAY "--> L0-D".
               MOVE 80 TO maxLen.
           END PROGRAM L0-D.
           END PROGRAM L0-A.
    

    it then compiled and ran successfully...

    F:\AA-minGW32-static>cobc -x bug897.cbl
    
    F:\AA-minGW32-static>BUG897
    --> L0-D
    
    F:\AA-minGW32-static>
    

    So I will mark this a closed as it is a simple coding mistake.

    ====> note that in program L0-D the maxLen variable was changed to a level 77 and the SET 80 TO maxLen was changed to be a MOVE rather than a SET (the SET verb is used to modify indexes, pointers).

     
  • meerkut

    meerkut - 2023-07-08

    I want to clarify that this error is not related to my demonstration code, which was specifically designed to showcase that there exists a byte sequence indicating a breakdown in the GNUCOBOL compiler's logic.

    This error is of utmost importance as it causes a complete the GNUCOBOL compiler crash.

    The issue at hand is as follows: when providing input data that contains "garbage" or incorrect values, the program unexpectedly terminates.

    Just for fun -- comment out, say, Line 19, in my demonstration code,
    where line 19 is:

    16|       MAIN.
    17|           DISPLAY "--> L0-B".
    18|           DISPLAY ss.
    19>           DISPLAY ss.
    20|       END PROGRAM L0-B.
    

    It then compiled.

    When testing a compiler for its resistance to incorrect input, there are several common testing techniques. These techniques help identify potential vulnerabilities and ensure the compiler handles invalid or malformed input gracefully. Here are some commonly used techniques:

    Boundary Testing: This technique involves testing inputs that are at the boundaries of the valid input range. It includes testing inputs with the minimum and maximum values allowed, as well as inputs just below or above these limits.

    Fuzz Testing: Fuzzing involves providing random or mutated inputs to the compiler to observe its behavior. The goal is to identify unexpected or undefined behavior caused by malformed input. Fuzz testing tools can generate a wide variety of input patterns to stress test the compiler.

    Negative Testing: Negative testing involves deliberately providing inputs that violate the expected rules or specifications. This includes inputs with syntax errors, conflicting declarations, or other forms of invalid code. The purpose is to verify that the compiler detects and reports errors correctly.

    Robustness Testing: This technique focuses on testing the compiler's ability to handle exceptional or unusual inputs gracefully. It includes testing inputs with missing or mismatched components, as well as unexpected or ambiguous constructs. The aim is to assess how well the compiler recovers from errors and produces meaningful error messages.

    .---
    Best regards

     
    • Chuck H.

      Chuck H. - 2023-07-08

      Meerkut,

      could you please run this command cobc --info
      then post the results here...

      here is the output from my environment (I just built the compiler on July 7, 2023).

      F:\AA-minGW32-static>cobc --info
      cobc (GnuCOBOL) 3.2-dev.0
      Copyright (C) 2023 Free Software Foundation, Inc.
      License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
      This is free software; see the source for copying conditions.  There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
      Built     Jul 07 2023 16:44:37
      Packaged  Jul 07 2023 14:16:01 UTC
      C version (MinGW) "13.1.0"
      
      build information
      build environment        : i686-w64-mingw32
      CC                       : gcc
      C version                : (MinGW) "13.1.0"
      CPPFLAGS                 : -I/mingw32/include
      CFLAGS                   : -O0 -ggdb3 -fasynchronous-unwind-tables -pipe
                                 -fsigned-char -Wall -Wwrite-strings
                                 -Wmissing-prototypes -Wno-format-y2k
      LD                       : R:/msys64/mingw32/i686-w64-mingw32/bin/ld.exe
      LDFLAGS                  :
      
      GnuCOBOL information
      COB_CC                   : gcc
      COB_CFLAGS               : -pipe -I/mingw32/include -I/mingw32/include
                                 -Wno-unused -fsigned-char -Wno-pointer-sign
      COB_DEBUG_FLAGS          : -ggdb3 -fasynchronous-unwind-tables
      COB_LDFLAGS              :
      COB_LIBS                 : -L/mingw32/lib -lcob
      COB_CONFIG_DIR           : /mingw32/share/gnucobol/config
        env: COB_CONFIG_DIR    : R:\msys64\mingw32\share\gnucobol\config
      COB_COPY_DIR             : /mingw32/share/gnucobol/copy
        env: COB_COPY_DIR      : R:\msys64\mingw32\share\gnucobol\copy
      COB_MSG_FORMAT           : GCC
      COB_OBJECT_EXT           : o
      COB_MODULE_EXT           : dll
      COB_EXE_EXT              : exe
      64bit-mode               : no
      BINARY-C-LONG            : 4 bytes
      endianness               : little-endian
      native EBCDIC            : no
      extended screen I/O      : pdcurses
      variable file format     : 0
      sequential file handler  : built-in
      indexed file handler     : BDB
      mathematical library     : GMP
      XML library              : libxml2
      JSON library             : cjson
      
      F:\AA-minGW32-static>
      

      with your original source posted above... and line 19 commented out...

      F:\AA-minGW32-static>cobc -x -o "bug897a" "bug897a.cbl"
      bug897a.cbl: in paragraph 'MAIN':
      bug897a.cbl:41: error: invalid SET statement
         39 |        MAIN.
         40 |            DISPLAY "--> L0-D".
         41 >            SET 80 TO maxLen.
         42 |        END PROGRAM L0-D.
         43 |        END PROGRAM L0-A.
      

      same compile error.....

      so I have not been able to reproduce the problem you mention using the source code you provided...

       
      • meerkut

        meerkut - 2023-07-08

        Chuck,
        Here is the output:

        $ cobc --info
        cobc (GnuCOBOL) 3.1.2.0
        Copyright (C) 2020 Free Software Foundation, Inc.
        License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
        This is free software; see the source for copying conditions.  There is NO
        warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
        Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
        Built     Jun 16 2023 04:35:55
        Packaged  Dec 23 2020 12:04:58 UTC
        C version "10.2.1 20210110"
        
        build information
        build environment        : x86_64-pc-linux-gnu
        CC                       : gcc
        C version                : "10.2.1 20210110"
        CPPFLAGS                 : 
        CFLAGS                   : -O2 -pipe -finline-functions -fsigned-char
                                   -Wall -Wwrite-strings -Wmissing-prototypes
                                   -Wno-format-y2k
        LD                       : /usr/bin/ld -m elf_x86_64
        LDFLAGS                  :  -Wl,-z,relro,-z,now,-O1
        
        GnuCOBOL information
        COB_CC                   : gcc
        COB_CFLAGS               : -pipe -I/usr/local/include -Wno-unused
                                   -fsigned-char -Wno-pointer-sign
        COB_DEBUG_FLAGS          : -ggdb3 -fasynchronous-unwind-tables
        COB_LDFLAGS              : 
        COB_LIBS                 : -L/usr/local/lib -lcob -lm
        COB_CONFIG_DIR           : /usr/local/share/gnucobol/config
        COB_COPY_DIR             : /usr/local/share/gnucobol/copy
        COB_MSG_FORMAT           : GCC
        COB_OBJECT_EXT           : o
        COB_MODULE_EXT           : so
        COB_EXE_EXT              : 
        64bit-mode               : yes
        BINARY-C-LONG            : 8 bytes
        endianness               : little-endian
        native EBCDIC            : no
        extended screen I/O      : ncursesw
        variable file format     : 0
        sequential file handler  : built-in
        indexed file handler     : BDB
        mathematical library     : GMP
        XML library              : disabled
        JSON library             : not found
        
         
    • Simon Sobisch

      Simon Sobisch - 2023-07-08

      Thank you for edge-testing the compiler! Complete chrashes are to prevented, but this specific issue was fixed.
      If you do edge case testing it is always most reasonable to recheck with the most current version (as @chaat did). So thanks to both of you for testing and for check-closing.

       
  • Simon Sobisch

    Simon Sobisch - 2023-07-08
    • labels: --> cobc, SIGSEGV
    • status: closed --> duplicate
    • Group: unclassified --> GC 3.2
    • Priority: 5 - default --> 3
     
  • Simon Sobisch

    Simon Sobisch - 2023-07-08

    Just out of curiosity I've had a look at this, starting with a debug version of the 3.1.2 compiler (that includes --enable-cobc-internal-checks which slows down the compiler) as most SIGSEGV are about internal casting issues and this does a data-driven check for the validity of casts.

    Result:

    cobc: typeck.c: 8877: invalid cast from '80' type LITERAL to type FIELD

    cobc: aborting compile of ../L0.cob at line 41 (PROGRAM-ID: L0-D)
    cobc: Please report this!

    Then I've compared the code around that with the current one and spot the additional check we now do there; svn annotate brought up the revision for that, so... fixed in [r4875], which has a good reference so we can also mark that as duplicate of [bugs:#643], which may would be able to find using the search option (you find that on the upper left of this page as "Search Bugs").

     

    Related

    Bugs: #643
    Commit: [r4875]


Log in to post a comment.