https://gcc.gnu.org/g:38898f9bdae4dc7db4db537a503c995b06a3f16b
commit r17-4423-g38898f9bdae4dc7db4db537a503c995b06a3f16b Author: Xavier Del Campo Romero <[email protected]> Date: Thu Sep 17 22:36:18 2026 +0200 cobol: Revert "cobol: Correct CBL_CREATE_FILE and improve parameter validation for ANY LENGTH." CBL_CREATE_FILE was creating files with a trailing '0', and this is an actual bug. For example, it created files such as "myfile.txt0" or "anotherfile0", instead of "myfile.txt" or "anotherfile". While it is assumed the intention was to null-terminate the input string instead, this is in fact redundant since posix-open already performs this operation. On the other hand, the string length validation logic should not rely on hardcoded values such as filename-max. Maximum filename length is already handled by the kernel e.g.: by returning ENAMETOOLONG from open(2). gcc/cobol/ChangeLog: * parse.y: Revert. * symbols.h: Likewise. libgcobol/ChangeLog: * compat/gnu/lib/CBL_CREATE_FILE.cbl: Likewise. Diff: --- gcc/cobol/parse.y | 11 +++-------- gcc/cobol/symbols.h | 6 ------ libgcobol/compat/gnu/lib/CBL_CREATE_FILE.cbl | 28 +++++++--------------------- 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index aa53e5f259f9..8219342856d8 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -12979,7 +12979,7 @@ cbl_ffi_arg_t::matches( const cbl_ffi_arg_t& that ) const { case by_reference_e: if( crv == by_reference_e ) { if( (formal->attr & mask) == (actual->attr & mask) ) { - if( capacity_ok(formal, actual) ) { + if( formal->data.capacity() == actual->data.capacity() ) { if( formal->type == actual->type ) { // captures USAGE except COMP-X return true; } @@ -12988,17 +12988,13 @@ cbl_ffi_arg_t::matches( const cbl_ffi_arg_t& that ) const { return true; } } - // If actual is by reference, so must the formal be. - dbgmsg("%s:%d: failed, reference feature mismatch", __func__, __LINE__); + // If actual is by reference, so must the formal be. return false; break; case by_content_e: break; case by_value_e: - if( crv != by_value_e ) { - dbgmsg("%s:%d: failed, actual %s not by value", __func__, __LINE__, actual->name); - return false; - } + if( crv != by_value_e ) return false; if( formal->type == FldPointer && that.refer.is_pointer() ) return true; break; } @@ -13015,7 +13011,6 @@ cbl_ffi_arg_t::matches( const cbl_ffi_arg_t& that ) const { return actual->data.capacity() == formal->data.capacity() && actual->codeset.encoding == formal->codeset.encoding; } - dbgmsg("%s:%d: failed, for some reason", __func__, __LINE__); return false; } diff --git a/gcc/cobol/symbols.h b/gcc/cobol/symbols.h index 6c6142ed1a93..3887b275b7b0 100644 --- a/gcc/cobol/symbols.h +++ b/gcc/cobol/symbols.h @@ -1444,12 +1444,6 @@ protected: if( crv == by_reference_e ) return false; return refer.field != NULL; } - static bool capacity_ok( const cbl_field_t *formal, const cbl_field_t *actual ) { - if( formal->data.capacity() == actual->data.capacity() ) return true; - if( formal->data.capacity() == 1 && formal->has_attr(any_length_e) ) return true; - if( actual->data.capacity() == 1 && actual->has_attr(any_length_e) ) return true; - return false; - } }; // In support of serial/linear search: diff --git a/libgcobol/compat/gnu/lib/CBL_CREATE_FILE.cbl b/libgcobol/compat/gnu/lib/CBL_CREATE_FILE.cbl index c1d6c5ebb378..911bde060fa4 100644 --- a/libgcobol/compat/gnu/lib/CBL_CREATE_FILE.cbl +++ b/libgcobol/compat/gnu/lib/CBL_CREATE_FILE.cbl @@ -47,20 +47,18 @@ 77 func-ret Binary-Long. 77 errno-val Binary-Long. 77 lk-mode PIC 9(8) COMP-5. - 01 filename-max CONSTANT AS 8 * 1024. - 01 filename PIC X(filename-max). 77 filename-len PIC 9(4) BINARY VALUE ZERO. 01 ws-access-mode PIC 9(8) COMP-5. LINKAGE SECTION. 77 RETCODE PIC X(2) COMP-5. - 01 Lk-filename PIC X ANY LENGTH. + 01 filename PIC X ANY LENGTH. 01 access-mode PIC x COMP-x. 01 deny-mode PIC x comp-x. *> Not supported (must be 0). 01 device PIC x comp-x. *> Not supported (must be 0). 01 file-handle PIC X(4) COMP-5. - PROCEDURE DIVISION USING Lk-filename, + PROCEDURE DIVISION USING filename, By Reference access-mode, By Reference deny-mode, By Reference device, @@ -74,7 +72,8 @@ END-IF. COMPUTE filename-len = - FUNCTION LENGTH(FUNCTION TRIM(Lk-filename)). + FUNCTION LENGTH(FUNCTION TRIM(filename)). + MOVE X"00" TO filename(filename-len + 1:1). D Display 'CBL_CREATE_FILE: filename: [' filename ']' D Display 'ws-access-mode: ' ws-access-mode ', ' D Display 'deny-mode: ' deny-mode. @@ -95,31 +94,18 @@ Compute ws-access-mode = ws-access-mode + O_CREAT + O_TRUNC. Compute Lk-mode = S_IRUSR + S_IWUSR + S_IRGRP + S_IWGRP. - IF Lk-filename(filename-len:1) = ZERO - MOVE FUNCTION posix-open(Lk-filename, - ws-access-mode, lk-mode) - TO func-ret - ELSE - IF filename-max < filename-len + 1 - MOVE 30 to RETCODE - GOBACK - END-IF - MOVE Lk-filename to filename - MOVE ZERO TO filename(filename-len + 1:1) - MOVE FUNCTION posix-open(filename, ws-access-mode, lk-mode) - TO func-ret - END-IF + MOVE FUNCTION posix-open(filename, ws-access-mode, lk-mode) + TO func-ret. If func-ret is < 0 Then Move Function COBRT-FILE-STATUS() to RETCODE D Display 'COBRT-FILE-STATUS returned: ' RETCODE - D ' for errno ' func-ret else Move func-ret to file-handle Move 0 to RETCODE end-if. - + END PROGRAM CBL_CREATE_FILE. >> POP SOURCE FORMAT
