Menu

#2493 Crash with -c flag and command line arguments

None
closed-fixed
nobody
None
2022-07-11
2022-02-09
No

Gnuplot crashes when it is invoked with a command such as gnuplot -c script.gpi 1 2. This happens with gnuplot 5.4.3 on Windows 10, in cmd.exe.

Steps to reproduce the bug:
Create this file, named script.gpi:

print('start')
print(ARG0)
print(ARG1)
print(ARG2)
print('end')

Do gnuplot -c script.gpi. The expected output is

start
script.gpi


end

but instead gnuplot crashes and does not output anything.
Do gnuplot -c script.gpi 1. The output matches the expected output:

start
script.gpi
1

end

No issue here.
Do gnuplot -c script.gpi 1 2. The expected output is

start
script.gpi
1
2
end

but instead gnuplot crashes and does not output anything.

Discussion

  • Ethan Merritt

    Ethan Merritt - 2022-02-10

    I'm not seeing a crash under linux, but valgrind shows a read from uninitialized memory that may explain it. The attached patch prevents that, and hopefully it also fixes your crash.

     
  • Tatsuro MATSUOKA

    In the current development source in which the above patch applied,

    gnuplot -c script.gpi
    

    still crashes.
    I tried make with debug symbol and tried execute through gdb.
    I made break point in misc,c however program seems to seg faults very early stage.

    (gdb) r -c /d/Work/Tatsuro/cygwinwork/gnuplot/bug_etcs/2493/script.gp
    Starting program: D:\Work\Tatsuro\msys2-gnuplot\gnuplot\gnuplot-main\gnuplot-main\config\mingw\gnuplot.exe -c /d/Work/Tatsuro/cygwinwork/gnuplot/bug_etcs/2493/script.gp
    [New Thread 7504.0x1e60]
    [New Thread 7504.0x19c8]
    [New Thread 7504.0xcb0]
    
    Thread 1 received signal SIGSEGV, Segmentation fault.
    0x00007ffb4ce3a3ee in msvcrt!_strdup () from C:\WINDOWS\System32\msvcrt.dll
    
     

    Last edit: Tatsuro MATSUOKA 2022-02-11
  • Bastian Märkisch

    • status: open --> pending-fixed
    • Group: -->
    • Priority: -->
     
  • Bastian Märkisch

    The index for the call arguments gets one too large which is causing the segfault. Fixed in master.

     
  • Tatsuro MATSUOKA

    I have confirmed the fix in the master branch. Commit [d78e63]

     

    Related

    Commit: [d78e63]

  • Ethan Merritt

    Ethan Merritt - 2022-07-11
    • Status: pending-fixed --> closed-fixed
     

Log in to post a comment.