bugGNU Octave - Bugs: bug #48665, calling continue in a function...

 
 

bug #48665: calling continue in a function outside of a conditional or loop silences stdout, may crash Octave

Submitted by:  None
Submitted on:  Mon 01 Aug 2016 04:43:29 AM UTC  
 
Category:  Interpreter Severity:  4 - Important
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  Fixed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  dev
Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Mon 31 Oct 2016 06:42:12 PM UTC, comment #8: 

Thanks for testing, finally pushed this to the stable branch in time for the 4.2 release.

http://hg.savannah.gnu.org/hgweb/octave/rev/d43094e91ba7

Mike Miller <mtmiller>
Project Administrator
Fri 28 Oct 2016 02:48:55 AM UTC, comment #7: 

This seems like a good fix.  I tried it with the test function foo from comment #3 and it segfaulted before, and passed after the patch.

I don't think there is a need to change the break keywoard. Using the foo script as before, but replacing continue with break, does not cause a segfault regardless of whether the patch is applied.

I tested on stable and the fix should probably go there.

Rik <rik5>
Project Administrator
Fri 28 Oct 2016 01:06:39 AM UTC, comment #6: 

This simple change fixes the bug for me. Should we make a similar change for the "break" keyword as well? Should we report an error when they are not called within a loop context?

diff --git a/libinterp/parse-tree/pt-eval.cc b/libinterp/parse-tree/pt-eval.cc
--- a/libinterp/parse-tree/pt-eval.cc
+++ b/libinterp/parse-tree/pt-eval.cc
@@ -115,8 +115,7 @@ namespace octave
     if (debug_mode)
       do_breakpoint (cmd.is_breakpoint (true));

-    if (statement_context == function || statement_context == script
-        || in_loop_command)
+    if (in_loop_command)
       tree_continue_command::continuing = 1;
   }

Mike Miller <mtmiller>
Project Administrator
Fri 28 Oct 2016 12:23:47 AM UTC, comment #5: 

The segfault here is due to the changes to how errors are handled and propagated. Whatever is happening with the "continue" in a user function, it is also preventing the error() function from behaving properly inside user functions. Since print_usage doesn't throw an error, the builtin function "all" with no arguments continues running as if it had valid args, and dereferences a bad pointer.

Observe


>> function foo, continue, endfunction;
>> foo
>> lasterr
ans =
>> error asdfasdfasdf;
error: asdfasdfasdf
>> lasterr
ans = asdfasdfasdf
>> lasterror reset;
>>
>> print_usage ("all")
>> lasterr
ans =

In 4.0 and earlier versions, we always followed print_usage with a return statement, so even if the error message was suppressed and the error state not correctly recorded, the builtin function still returned control early.

Mike Miller <mtmiller>
Project Administrator
Wed 10 Aug 2016 04:00:32 AM UTC, comment #4: 

Confirmed.  With versions <= 4.0.3 the bare continue keyword still suppressed output, but using a built-in function like 'all' didn't result in a segfault.

Rik <rik5>
Project Administrator
Mon 01 Aug 2016 04:19:47 PM UTC, comment #3: 

Thank you for your bug report. You are asking for support with a problem on a bug report, which is not a correct use of this medium. I was about to close this and suggest that you should seek out support channels instead, but it looks like you have hit an actual bug, so I'm repurposing this report for that bug.

The following function causes all output in Octave to be suppressed after calling the function:

function foo ()
  continue;
endfunction

After calling `foo`, most standard output to the screen is suppressed, unless calling a function like disp or printf directly.

In addition, calling a builtin function with invalid arguments triggers a segfault:

>> all
error: Invalid call to all.  Correct usage is:

-- all (X)
-- all (X, DIM)

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at http://www.octave.org and via the help@octave.org
mailing list.
>> foo
>> all
panic: Segmentation fault -- stopping myself...
attempting to save variables to 'octave-workspace'...
save to 'octave-workspace' complete
Segmentation fault

Mike Miller <mtmiller>
Project Administrator
Mon 01 Aug 2016 07:57:44 AM UTC, comment #2: 

Hi.you can try a different way of giving default values.this should work.i'll try attach a edited copy of your function.

(file #38063)

Asanka <madushan>
Mon 01 Aug 2016 05:00:42 AM UTC, comment #1: 

I am who post the bug and I have new problem. I tried to erase default arguments, and save function. And I put all of the arguments but it is not work. It not print any error message and strange result like below.

----------

>> asm(img,"out",0,1,201)

z0 = 0

>> asm(img,"out",0,1)

z0 = 0

>>

---------

First, it until do not proceed after print arguments.
Second, after octave relaunched, the function without default arguments works well.

Is it memory problems?

Anonymous
Mon 01 Aug 2016 04:43:29 AM UTC, original submission:  

My function, attached m-file, works well without default arguments. But after I put default arguments, it gets default value and stops. Another strange thing is, in second try, it just execute only first sequence. In my case it looks like below.

-----------

>> asm(img)

z0 = 0
z1 =  1
N =  201
out = 0

>> asm(img)

z0 = 0

>>

-----------

I do not have any idea to fix it. I think is a bug. Please fix it or teach my fault if it is.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #38063:  asm.m added by madushan (2KiB - text/x-objcsrc)
file #38060:  asm.m added by None (1KiB - text/x-objcsrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by madushan (Updated the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-10-31 mtmiller StatusPatch Submitted => Fixed
        Open/ClosedOpen => Closed
    2016-10-28 mtmiller StatusConfirmed => Patch Submitted
    2016-08-10 rik5 StatusNone => Confirmed
    2016-08-01 mtmiller CategoryOctave Function => Interpreter
        Severity3 - Normal => 4 - Important
        Item GroupIncorrect Result => Segfault, Bus Error, etc.
        Release4.0.2 => dev
        SummaryAfter put dufault value, function does not work any more. => calling continue in a function outside of a conditional or loop silences stdout, may crash Octave
    2016-08-01 madushan Attached File- => Added asm.m, #38063
    2016-08-01 None Attached File- => Added asm.m, #38060

    Back to the top


    Powered by Savane 3.5