bugmake - Bugs: bug #65019, Let function segfaults when...

 
 

bug #65019: Let function segfaults when foreach return empty list

Submitter:  John Olsson <ermingol>
Submitted:  Tue 12 Dec 2023 12:47:49 PM UTC
   
 
Severity:  3 - Normal Item Group:  Bug
Status:  Fixed Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Component Version:  4.4 Operating System:  Any
Fixed Release:  SCM Triage Status:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 08 Jan 2024 06:04:13 PM UTC, comment #4: 

Thanks for applying! If I'm not mistaken, I had put a reference in the subject and git am would have included it in the commit message.

Jouke Witteveen <jwitteveen>
Sun 07 Jan 2024 03:33:53 PM UTC, comment #3: 

Applied, thanks Jouke.

FYI please remember to include a reference to the bug# in the Git commit message.  Unfortunately I forgot to add it by hand when I applied your patch.

Paul D. Smith <psmith>
Group administrator
Tue 12 Dec 2023 10:35:43 PM UTC, comment #2: 

The attached patch should fix the issue and prevent regressions.

(file #55442)

Jouke Witteveen <jwitteveen>
Tue 12 Dec 2023 01:48:02 PM UTC, comment #1: 

You are right! An even shorter way to reproduce the segfault is with

$(let a b, ,)

Having more than one variable is needed to trigger the bug. Without the whitespace in the value list, the bug also does not trigger.

I believe the following will fix it. I hope to prepare a patch with some tests later.

diff --git a/src/function.c b/src/function.c
index a705c8a0..4596bd90 100644
--- a/src/function.c
+++ b/src/function.c
@@ -927,7 +927,7 @@ func_let (char o, char *argv, const char *funcname UNUSED)
   while (*vp_next != '\0')
     {
       p = find_next_token (&list_iterator, &len);
-      if (*list_iterator != '\0')
+      if (p && *list_iterator != '\0')
         {
           ++list_iterator;
           p[len] = '\0';

Jouke Witteveen <jwitteveen>
Tue 12 Dec 2023 12:47:49 PM UTC, original submission:  

The following Makefile segfaults when the return value from the foreach function is assigned to the two local variables 'result' and 'rest' AND the forach function return an empty list.

To reproduce the segmentation fault run the Makefile below in a folder which does not contain the folder 'fum' with file 'foo.txt'. Once 'fum/foo.txt' exist there is no segfault.

I have only verified this on CentOS 7.9.

define foobar
$(info foobar: $(1))
$(let file folderlist,$(1) $(2),\
      $(info file='$(file)'  folderlist='$(folderlist)')
      $(let result rest,\
            $(foreach folder,$(folderlist),\
                      $(wildcard $(folder)/$(file))),\
                      $(info result='$(result)' rest='$(rest)')))
endef

$(call foobar,foo.txt,fum)

.PHONY: all
all:
@:

John Olsson <ermingol>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #55442:  SV-65019-Fix-let-segfault-on-value-with-trailing-whi.patch added by jwitteveen (1KiB - text/x-patch - Fix let segfault on value with trailing whitespace)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by psmith (Posted a comment)
  • -email is unavailable- added by jwitteveen (Posted a comment)
  • -email is unavailable- added by ermingol (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-01-07 psmith StatusNone Fixed
        Open/ClosedOpen Closed
        Operating SystemNone Any
        Fixed ReleaseNone SCM
    2023-12-12 jwitteveen Attached File- Added SV-65019-Fix-let-segfault-on-value-with-trailing-whi.patch, #55442

    Back to the top

    Powered by Savane 3.13-04b1.
    Corresponding source code