Bug 53521 - crash when running "shell()" with a non-existent program
Summary: crash when running "shell()" with a non-existent program
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
3.6.0.4 release
Hardware: Other All
: medium normal
Assignee: Christopher Copits
URL:
Whiteboard: target:4.1.0 target:4.0.0.1 target:3.6.5
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-15 02:38 UTC by Marc Sabatella
Modified: 2013-01-07 18:57 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Sabatella 2012-08-15 02:38:42 UTC
Pretty straightforward, really - the following sub crashes LibreOffice on my system (3.6.0.4, Windows 8).  Sometimes it runs once and catches the error, and the second run crashes:

Sub crashMe
on error goto noExist
	shell("doesnotexist")
	exit Sub
noExist:
	msgbox("caught error")
End Sub

I see this related post on the OOo site:

http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=54752

(pertains to LO 3.5.4 on Linux; same exact symptoms)
Comment 1 Christina Rossmanith 2012-09-26 18:05:05 UTC
Reproducible with:

LibreOffice 3.5.4.2 
Build ID: 350m1(Build:2)

and

Version 3.7.0.0.alpha0+ (Build ID: 784302d)
Comment 2 Christopher Copits 2012-12-20 21:58:17 UTC
I can reproduce this, and I am working on fixing it.
Comment 3 Christopher Copits 2013-01-01 21:40:58 UTC
To reproduce the bug in existing code:

1. Click Tools > Macros > Organize Macros > LibreOffice BASIC;
2. On the left pane ("Macro From Field"), Navigate to My Macros > Standard > Module1 (or wherever you want to test);
3. On the right pane ("Existing Macros In"), select "main";
4. Click the "Edit" button;
5. Paste in the following code:

Sub crashMe
on error goto noExist
	shell("doesnotexist")
	exit Sub
noExist:
	msgbox("caught error")
End Sub

6. Press F5;
7. Observe that LO crashes.

After my change:

1. Click Tools > Macros > Organize Macros > LibreOffice BASIC;
2. On the left pane ("Macro From Field"), Navigate to My Macros > Standard > Module1 (or wherever you want to test);
3. On the right pane ("Existing Macros In"), select "main";
4. Click the "Edit" button;
5. Paste in the following code:

Sub crashMe
on error goto noExist
	shell("doesnotexist")
	exit Sub
noExist:
	msgbox("caught error")
End Sub

6. Press F5;
7. Observe that the message box contains the following:

BASIC runtime error.
File not found.

However, ensure that LO does not crash.

You can also verify that using shell to execute an existing program still works.
For example, instead of executing "doesnotexist," you might try "notepad" (for Windows) or
"gedit" (for many versions of Linux).

What I am changing:

I am checking bSucc to make sure that osl_executeProcess was successful. If bSucc is false, there is no need to free the handle.

The problem is that the process handle is freed regardless of whether osl_executeProcess was successful or not. Therefore, a segmentation fault would result, as a random memory address would be freed. This patch checks whether osl_executeProcess was successful. If it was, then it frees the handle; if it wasn't successful, the memory is not freed.
Comment 4 Not Assigned 2013-01-07 14:04:54 UTC
Christopher Copits committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=dbfc8777bf73872d1b96f956b9e778d9099d52b3

fdo#53521 Crash when running BASIC's "shell()" with a non-existent program



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 5 Not Assigned 2013-01-07 16:00:43 UTC
Christopher Copits committed a patch related to this issue.
It has been pushed to "libreoffice-4-0":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=96b985145b3efbaf4552adbeccf24bfac2fa71b0&h=libreoffice-4-0

fdo#53521 Crash when running BASIC's "shell()" with a non-existent program


It will be available in LibreOffice 4.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 6 Not Assigned 2013-01-07 16:07:22 UTC
Christopher Copits committed a patch related to this issue.
It has been pushed to "libreoffice-3-6":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=ccd30d3bb395fd367d8b687fc2b3b13641c8d846&h=libreoffice-3-6

fdo#53521 Crash when running BASIC's "shell()" with a non-existent program


It will be available in LibreOffice 3.6.5.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 7 Michael Stahl (allotropia) 2013-01-07 18:57:20 UTC
this bug should be fixed now on all active release branches,
thanks Christopher Copits for the patch!