#998642 cssc: The "get" command fails to interpolate the "module name" for long filenames

Package:
cssc
Source:
cssc
Description:
Clone of the Unix SCCS revision-control system
Submitter:
John Hughes
Date:
2026-08-31 16:31:00 UTC
Severity:
normal
#998642#5
Date:
2021-11-05 13:10:11 UTC
From:
To:
Dear Maintainer,

   * What led up to the situation?

We found that the %M% SCCS keyword in some of our files was not being correctly
interpolated.

   * What exactly did you do (or not do) that was effective (or
     ineffective)?

Did a "get" on a file called s.xxxx_xxxxxxxxx-xx

   * What was the outcome of this action?

In the created file xxxx_xxxxxxxxx-xx the %M% keyword was replaced by an
empty string instead of the module name xxxx_xxxxxxxxx-xx

   * What outcome did you expect instead?

That %M% be replaced by xxxx_xxxxxxxxx-xx

This used to work with older versions of cssc.

I have tried running "get" under valgrind and was surprised to see "Invalid
read" errors:

$ valgrind /usr/lib/x86_64-linux-gnu/cssc/get -t "SCCS/s.xxxx_xxxxxxxxx-xx"
==24638== Memcheck, a memory error detector
==24638== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==24638== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==24638== Command: /usr/lib/x86_64-linux-gnu/cssc/get -t SCCS/s.xxxx_xxxxxxxxx-xx
==24638==
==24638== Invalid read of size 1
==24638==    at 0x4838CC2: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==24638==    by 0x4BF84A4: fputs (iofputs.c:33)
==24638==    by 0x111F27: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x112057: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x110EF0: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x10FBD0: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x10CBAA: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x4BAC09A: (below main) (libc-start.c:308)
==24638==  Address 0x4d685a0 is 0 bytes inside a block of size 18 free'd
==24638==    at 0x4836EAB: operator delete(void*) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==24638==    by 0x111F1C: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x112057: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x110EF0: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x10FBD0: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x10CBAA: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x4BAC09A: (below main) (libc-start.c:308)
==24638==  Block was alloc'd at
==24638==    at 0x4835DEF: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==24638==    by 0x10E56C: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x114165: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x111F05: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x112057: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x110EF0: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x10FBD0: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x10CBAA: ??? (in /usr/lib/x86_64-linux-gnu/cssc/get)
==24638==    by 0x4BAC09A: (below main) (libc-start.c:308)
==24638==

#998642#10
Date:
2021-11-05 13:29:35 UTC
From:
To:
I built cssc from source to get the debug symbols and valgrind shows:

valgrind cssc-1.4.1/src/get  s.xxxx_xxxxxxxxx-xx
==319086== Memcheck, a memory error detector
==319086== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==319086== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==319086== Command: cssc-1.4.1/src/get s.xxxx_xxxxxxxxx-xx
==319086==
==319086== Invalid read of size 1
==319086==    at 0x483BC82: strlen (vg_replace_strmem.c:459)
==319086==    by 0x4AC5F34: fputs (iofputs.c:33)
==319086==    by 0x111B59: sccs_file::write_subst(char const*, sccs_file::subst_parms*, delta const&, bool) const (writesubst.cc:113)
==319086==    by 0x111CED: sccs_file::write_subst(char const*, sccs_file::subst_parms*, delta const&, bool) const (writesubst.cc:245)
==319086==    by 0x110BFD: sccs_file::get(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, seq_state&, sccs_file::subst_parms&, bool, int, int, int, bool, bool) (sf-get.cc:416)
==319086==    by 0x10FAAA: sccs_file::get(_IO_FILE*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _IO_FILE*, sid, sccs_date, range_list<sid>, range_list<sid>, int, char const*, int, int, int, bool) (sf-get2.cc:519)
==319086==    by 0x10C88B: main (get.cc:463)
==319086==  Address 0x4d75c80 is 0 bytes inside a block of size 18 free'd
==319086==    at 0x483A08B: operator delete(void*, unsigned long) (vg_replace_malloc.c:593)
==319086==    by 0x111B4B: deallocate (new_allocator.h:133)
==319086==    by 0x111B4B: deallocate (alloc_traits.h:492)
==319086==    by 0x111B4B: _M_destroy (basic_string.h:237)
==319086==    by 0x111B4B: _M_dispose (basic_string.h:232)
==319086==    by 0x111B4B: ~basic_string (basic_string.h:658)
==319086==    by 0x111B4B: sccs_file::write_subst(char const*, sccs_file::subst_parms*, delta const&, bool) const (writesubst.cc:112)
==319086==    by 0x111CED: sccs_file::write_subst(char const*, sccs_file::subst_parms*, delta const&, bool) const (writesubst.cc:245)
==319086==    by 0x110BFD: sccs_file::get(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, seq_state&, sccs_file::subst_parms&, bool, int, int, int, bool, bool) (sf-get.cc:416)
==319086==    by 0x10FAAA: sccs_file::get(_IO_FILE*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _IO_FILE*, sid, sccs_date, range_list<sid>, range_list<sid>, int, char const*, int, int, int, bool) (sf-get2.cc:519)
==319086==    by 0x10C88B: main (get.cc:463)
==319086==  Block was alloc'd at
==319086==    at 0x4838DEF: operator new(unsigned long) (vg_replace_malloc.c:342)
==319086==    by 0x11297C: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) [clone .isra.0] (basic_string.tcc:219)
==319086==    by 0x113301: _M_construct_aux<char*> (basic_string.h:247)
==319086==    by 0x113301: _M_construct<char*> (basic_string.h:266)
==319086==    by 0x113301: basic_string (basic_string.h:451)
==319086==    by 0x113301: gfile (sccsname.h:87)
==319086==    by 0x113301: sccs_file::get_module_name[abi:cxx11]() const (sccsfile.cc:694)
==319086==    by 0x111B2B: sccs_file::write_subst(char const*, sccs_file::subst_parms*, delta const&, bool) const (writesubst.cc:112)
==319086==    by 0x111CED: sccs_file::write_subst(char const*, sccs_file::subst_parms*, delta const&, bool) const (writesubst.cc:245)
==319086==    by 0x110BFD: sccs_file::get(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, seq_state&, sccs_file::subst_parms&, bool, int, int, int, bool, bool) (sf-get.cc:416)
==319086==    by 0x10FAAA: sccs_file::get(_IO_FILE*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, _IO_FILE*, sid, sccs_date, range_list<sid>, range_list<sid>, int, char const*, int, int, int, bool) (sf-get2.cc:519)
==319086==    by 0x10C88B: main (get.cc:463)
==319086==

So this patch fixes the problem:
--- src/writesubst.cc.orig 2019-05-07 13:40:13.000000000 +0200 +++ src/writesubst.cc 2021-11-05 14:26:23.229149292 +0100 @@ -109,8 +109,8 @@ case 'M': { - const char *mod = get_module_name().c_str(); - err = fputs_failed(fputs(mod, out)); + string mod = get_module_name(); + err = fputs_failed(fputs(mod.c_str(), out)); } break;
#998642#15
Date:
2026-08-31 16:20:22 UTC
From:
To: