summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authorAdeline CARNIS <adeline.carnis@scilab-enterprises.com>2016-09-23 15:44:09 +0200
committerAntoine ELIAS <antoine.elias@scilab-enterprises.com>2016-11-04 14:37:31 +0100
commitf977d1c899ff41315700c441ddc43095fd954727 (patch)
tree6ee907796794e5f7c6313e9a1ac11cab3c9b0d52 /scilab
parentde07a98f0ab0d4a9df431a0374fdf56c68634f91 (diff)
downloadscilab-f977d1c899ff41315700c441ddc43095fd954727.zip
scilab-f977d1c899ff41315700c441ddc43095fd954727.tar.gz
* Bug #13620 fixed - dos function called with a vector as input crashed.
Change-Id: If16cc437e94ac32a831ec436cc1d1578c6f0f7a1
Diffstat (limited to 'scilab')
-rw-r--r--scilab/CHANGES.md1
-rw-r--r--scilab/modules/windows_tools/sci_gateway/cpp/sci_dos.cpp246
-rw-r--r--scilab/modules/windows_tools/tests/nonreg_tests/bug_13620.dia.ref21
-rw-r--r--scilab/modules/windows_tools/tests/nonreg_tests/bug_13620.tst25
4 files changed, 161 insertions, 132 deletions
diff --git a/scilab/CHANGES.md b/scilab/CHANGES.md
index 250a6f7..57827bc 100644
--- a/scilab/CHANGES.md
+++ b/scilab/CHANGES.md
@@ -340,6 +340,7 @@ Bug Fixes
340* [#13583](http://bugzilla.scilab.org/show_bug.cgi?id=13583): `getd` loading a script including a `clear` instruction yielded an error 340* [#13583](http://bugzilla.scilab.org/show_bug.cgi?id=13583): `getd` loading a script including a `clear` instruction yielded an error
341* [#13597](http://bugzilla.scilab.org/show_bug.cgi?id=13597): `help format` claimed setting a number of digits instead of characters 341* [#13597](http://bugzilla.scilab.org/show_bug.cgi?id=13597): `help format` claimed setting a number of digits instead of characters
342* [#13613](http://bugzilla.scilab.org/show_bug.cgi?id=13613): `isdef(name, 'l')` produced wrong output. 342* [#13613](http://bugzilla.scilab.org/show_bug.cgi?id=13613): `isdef(name, 'l')` produced wrong output.
343* [#13620](http://bugzilla.scilab.org/show_bug.cgi?id=13620): `dos` called with a vector as input crashed.
343* [#13757](http://bugzilla.scilab.org/show_bug.cgi?id=13757): The toolbox menu dit not load properly ATOMS modules not autoloaded. 344* [#13757](http://bugzilla.scilab.org/show_bug.cgi?id=13757): The toolbox menu dit not load properly ATOMS modules not autoloaded.
344* [#13878](http://bugzilla.scilab.org/show_bug.cgi?id=13878): tokens([]) returns []. 345* [#13878](http://bugzilla.scilab.org/show_bug.cgi?id=13878): tokens([]) returns [].
345* [#13895](http://bugzilla.scilab.org/show_bug.cgi?id=13895): p.a.h = 1; p.b.h = 3; p(:).h CRASH 346* [#13895](http://bugzilla.scilab.org/show_bug.cgi?id=13895): p.a.h = 1; p.b.h = 3; p(:).h CRASH
diff --git a/scilab/modules/windows_tools/sci_gateway/cpp/sci_dos.cpp b/scilab/modules/windows_tools/sci_gateway/cpp/sci_dos.cpp
index 7fc0d75..b5497c1 100644
--- a/scilab/modules/windows_tools/sci_gateway/cpp/sci_dos.cpp
+++ b/scilab/modules/windows_tools/sci_gateway/cpp/sci_dos.cpp
@@ -42,9 +42,7 @@ int sci_dos(char *fname, void* pvApiCtx)
42 SciErr sciErr; 42 SciErr sciErr;
43 int *piAddressVarOne = NULL; 43 int *piAddressVarOne = NULL;
44 int iType1 = 0; 44 int iType1 = 0;
45 int m1 = 0, n1 = 0;
46 wchar_t *pStVarOne = NULL; 45 wchar_t *pStVarOne = NULL;
47 int lenStVarOne = 0;
48 46
49 char **Output = NULL; 47 char **Output = NULL;
50 int numberoflines = 0; 48 int numberoflines = 0;
@@ -149,176 +147,160 @@ int sci_dos(char *fname, void* pvApiCtx)
149 return 0; 147 return 0;
150 } 148 }
151 149
152 sciErr = getMatrixOfString(pvApiCtx, piAddressVarOne, &m1, &n1, &lenStVarOne, NULL); 150 if (isScalar(pvApiCtx, piAddressVarOne) == FALSE)
153 if (sciErr.iErr)
154 { 151 {
155 printError(&sciErr, 0); 152 Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 1);
156 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
157 return 0; 153 return 0;
158 } 154 }
159 155
160 if ( (m1 != n1) && (n1 != 1) ) 156 if (getAllocatedSingleWideString(pvApiCtx, piAddressVarOne, &pStVarOne))
161 { 157 {
162 Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 1); 158 printError(&sciErr, 0);
159 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
163 return 0; 160 return 0;
164 } 161 }
165 162
166 pStVarOne = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarOne + 1)); 163 double exitCode = 0.;
167 if (pStVarOne) 164 BOOL DetachProcessOption = FALSE;
168 { 165 BOOL *StatusExit = NULL;
169 double exitCode = 0.;
170 BOOL DetachProcessOption = FALSE;
171 BOOL *StatusExit = NULL;
172
173 sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, &lenStVarOne, &pStVarOne);
174 if (sciErr.iErr)
175 {
176 printError(&sciErr, 0);
177 Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
178 return 0;
179 }
180 166
181 DetachProcessOption = DetectDetachProcessInCommandLine(pStVarOne); 167 DetachProcessOption = DetectDetachProcessInCommandLine(pStVarOne);
182 exitCode = (double)spawncommand(pStVarOne, DetachProcessOption); 168 exitCode = (double)spawncommand(pStVarOne, DetachProcessOption);
183 FREE(pStVarOne); 169 freeAllocatedSingleWideString(pStVarOne);
184 170
185 StatusExit = (BOOL*)MALLOC(sizeof(BOOL)); 171 StatusExit = (BOOL*)MALLOC(sizeof(BOOL));
186 172
187 if (DetachProcessOption) 173 if (DetachProcessOption)
174 {
175 if (strlen((const char *)(pipeSpawnErr.OutputBuffer)))
188 { 176 {
189 if ( strlen((const char *)(pipeSpawnErr.OutputBuffer)) ) 177 /* StdErr will be "Output" */
190 { 178 *StatusExit = FALSE;
191 /* StdErr will be "Output" */ 179 Output = CreateOuput(&pipeSpawnErr, DetachProcessOption);
192 *StatusExit = FALSE; 180 numberoflines = pipeSpawnErr.NumberOfLines;
193 Output = CreateOuput(&pipeSpawnErr, DetachProcessOption);
194 numberoflines = pipeSpawnErr.NumberOfLines;
195 }
196 else
197 {
198 /* StdOut will be "Output" */
199 *StatusExit = TRUE;
200 Output = CreateOuput(&pipeSpawnOut, DetachProcessOption);
201 numberoflines = pipeSpawnOut.NumberOfLines;
202 }
203 } 181 }
204 else 182 else
205 { 183 {
206 char FileTMPDir[PATH_MAX + 16]; 184 /* StdOut will be "Output" */
207 BOOL bConvert = FALSE; 185 *StatusExit = TRUE;
186 Output = CreateOuput(&pipeSpawnOut, DetachProcessOption);
187 numberoflines = pipeSpawnOut.NumberOfLines;
188 }
189 }
190 else
191 {
192 char FileTMPDir[PATH_MAX + 16];
193 BOOL bConvert = FALSE;
208 194
209 char *TMPDirLong = getTMPDIR(); 195 char *TMPDirLong = getTMPDIR();
210 char *TMPDirShort = getshortpathname(TMPDirLong, &bConvert); 196 char *TMPDirShort = getshortpathname(TMPDirLong, &bConvert);
211 197
212 sprintf(FileTMPDir, "%s\\DOS.OK", TMPDirLong); 198 sprintf(FileTMPDir, "%s\\DOS.OK", TMPDirLong);
213 FREE(TMPDirLong); 199 FREE(TMPDirLong);
214 TMPDirLong = NULL; 200 TMPDirLong = NULL;
215 FREE(TMPDirShort); 201 FREE(TMPDirShort);
216 TMPDirShort = NULL; 202 TMPDirShort = NULL;
217 203
218 if (FileExist(FileTMPDir)) 204 if (FileExist(FileTMPDir))
219 { 205 {
220 DeleteFile(FileTMPDir); 206 DeleteFile(FileTMPDir);
221 /* StdOut will be "Output" */ 207 /* StdOut will be "Output" */
222 *StatusExit = TRUE; 208 *StatusExit = TRUE;
223 Output = CreateOuput(&pipeSpawnOut, DetachProcessOption); 209 Output = CreateOuput(&pipeSpawnOut, DetachProcessOption);
224 numberoflines = pipeSpawnOut.NumberOfLines; 210 numberoflines = pipeSpawnOut.NumberOfLines;
225 }
226 else
227 {
228 /* StdErr will be "Output" */
229 *StatusExit = FALSE;
230 Output = CreateOuput(&pipeSpawnErr, DetachProcessOption);
231 numberoflines = pipeSpawnErr.NumberOfLines;
232 }
233 } 211 }
234 212 else
235 if (ECHOMODE)
236 { 213 {
237 PrintOuput(Output, numberoflines); 214 /* StdErr will be "Output" */
215 *StatusExit = FALSE;
216 Output = CreateOuput(&pipeSpawnErr, DetachProcessOption);
217 numberoflines = pipeSpawnErr.NumberOfLines;
238 } 218 }
219 }
220
221 if (ECHOMODE)
222 {
223 PrintOuput(Output, numberoflines);
224 }
239 225
240 if (Lhs == 1) 226 if (Lhs == 1)
227 {
228 int m_out = 1, n_out = 1;
229 sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 1, m_out, n_out, StatusExit);
230 if (sciErr.iErr)
241 { 231 {
242 int m_out = 1, n_out = 1; 232 printError(&sciErr, 0);
243 sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 1, m_out, n_out, StatusExit); 233 Scierror(999, _("%s: Memory allocation error.\n"), fname);
244 if (sciErr.iErr) 234 return 0;
245 { 235 }
246 printError(&sciErr, 0);
247 Scierror(999, _("%s: Memory allocation error.\n"), fname);
248 return 0;
249 }
250 236
251 LhsVar(1) = Rhs + 1; 237 LhsVar(1) = Rhs + 1;
238 }
239 else
240 {
241 int m_out2 = 1;
242 int n_out2 = 1;
243
244 if (Output && Output[0])
245 {
246 int m_out1 = numberoflines;
247 int n_out1 = 1;
248 sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m_out1, n_out1, Output);
252 } 249 }
253 else 250 else
254 { 251 {
255 int m_out2 = 1; 252 /* returns [] */
256 int n_out2 = 1; 253 int m_out1 = 0;
257 254 int n_out1 = 0;
258 if (Output && Output[0]) 255 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m_out1, n_out1, NULL);
259 { 256 }
260 int m_out1 = numberoflines;
261 int n_out1 = 1;
262 sciErr = createMatrixOfString(pvApiCtx, Rhs + 1, m_out1, n_out1, Output);
263 }
264 else
265 {
266 /* returns [] */
267 int m_out1 = 0;
268 int n_out1 = 0;
269 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m_out1, n_out1, NULL);
270 }
271 257
272 if (sciErr.iErr) 258 if (sciErr.iErr)
273 { 259 {
274 printError(&sciErr, 0); 260 printError(&sciErr, 0);
275 Scierror(999, _("%s: Memory allocation error.\n"), fname); 261 Scierror(999, _("%s: Memory allocation error.\n"), fname);
276 return 0; 262 return 0;
277 } 263 }
278 264
279 LhsVar(1) = Rhs + 1; 265 LhsVar(1) = Rhs + 1;
280 266
281 sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 2, m_out2, n_out2, StatusExit); 267 sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 2, m_out2, n_out2, StatusExit);
282 if (sciErr.iErr) 268 if (sciErr.iErr)
283 { 269 {
284 printError(&sciErr, 0); 270 printError(&sciErr, 0);
285 Scierror(999, _("%s: Memory allocation error.\n"), fname); 271 Scierror(999, _("%s: Memory allocation error.\n"), fname);
286 return 0; 272 return 0;
287 }
288
289 LhsVar(2) = Rhs + 2;
290 } 273 }
291 274
292 if (Lhs > 2) 275 LhsVar(2) = Rhs + 2;
293 { 276 }
294 int m_out3 = 1, n_out3 = 1;
295 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 3, m_out3, n_out3, &exitCode);
296 if (sciErr.iErr)
297 {
298 printError(&sciErr, 0);
299 Scierror(999, _("%s: Memory allocation error.\n"), fname);
300 return 0;
301 }
302 277
303 LhsVar(3) = Rhs + 3; 278 if (Lhs > 2)
304 } 279 {
305 if (StatusExit) 280 int m_out3 = 1, n_out3 = 1;
281 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 3, m_out3, n_out3, &exitCode);
282 if (sciErr.iErr)
306 { 283 {
307 FREE(StatusExit); 284 printError(&sciErr, 0);
308 StatusExit = NULL; 285 Scierror(999, _("%s: Memory allocation error.\n"), fname);
286 return 0;
309 } 287 }
310 freeArrayOfString(Output, numberoflines);
311 288
312 ClosePipeInfo (pipeSpawnOut); 289 LhsVar(3) = Rhs + 3;
313 ClosePipeInfo (pipeSpawnErr);
314
315 PutLhsVar();
316 } 290 }
317 else 291 if (StatusExit)
318 { 292 {
319 Scierror(999, _("%s: No more memory.\n"), fname); 293 FREE(StatusExit);
294 StatusExit = NULL;
320 } 295 }
321 296
297 freeArrayOfString(Output, numberoflines);
298
299 ClosePipeInfo(pipeSpawnOut);
300 ClosePipeInfo(pipeSpawnErr);
301
302 PutLhsVar();
303
322 return 0; 304 return 0;
323} 305}
324/*--------------------------------------------------------------------------*/ 306/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/windows_tools/tests/nonreg_tests/bug_13620.dia.ref b/scilab/modules/windows_tools/tests/nonreg_tests/bug_13620.dia.ref
new file mode 100644
index 0000000..2934fee
--- /dev/null
+++ b/scilab/modules/windows_tools/tests/nonreg_tests/bug_13620.dia.ref
@@ -0,0 +1,21 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2016 - Scilab Enterprises - Adeline CARNIS
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// <-- CLI SHELL MODE -->
8// <-- Non-regression test for bug 13620 -->
9//
10// <-- Bugzilla URL -->
11// http://bugzilla.scilab.org/show_bug.cgi?id=13620
12//
13// <-- Short Description -->
14// dos function called with a vector as input crashed.
15// =============================================================================
16assert_checkfalse(execstr("dos([""dir"", ""dir""])" ,"errcatch") == 0);
17refMsg = msprintf(_("%s: Wrong size for input argument #%d: string expected.\n"), "dos", 1);
18assert_checkerror("dos([""dir"", ""dir""])", refMsg);
19assert_checkfalse(execstr("dos([""dir""; ""dir""])" ,"errcatch") == 0);
20refMsg = msprintf(_("%s: Wrong size for input argument #%d: string expected.\n"), "dos", 1);
21assert_checkerror("dos([""dir"", ""dir""])", refMsg);
diff --git a/scilab/modules/windows_tools/tests/nonreg_tests/bug_13620.tst b/scilab/modules/windows_tools/tests/nonreg_tests/bug_13620.tst
new file mode 100644
index 0000000..d5b409c
--- /dev/null
+++ b/scilab/modules/windows_tools/tests/nonreg_tests/bug_13620.tst
@@ -0,0 +1,25 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2016 - Scilab Enterprises - Adeline CARNIS
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7
8// <-- CLI SHELL MODE -->
9
10// <-- Non-regression test for bug 13620 -->
11//
12// <-- Bugzilla URL -->
13// http://bugzilla.scilab.org/show_bug.cgi?id=13620
14//
15// <-- Short Description -->
16// dos function called with a vector as input crashed.
17// =============================================================================
18
19assert_checkfalse(execstr("dos([""dir"", ""dir""])" ,"errcatch") == 0);
20refMsg = msprintf(_("%s: Wrong size for input argument #%d: string expected.\n"), "dos", 1);
21assert_checkerror("dos([""dir"", ""dir""])", refMsg);
22
23assert_checkfalse(execstr("dos([""dir""; ""dir""])" ,"errcatch") == 0);
24refMsg = msprintf(_("%s: Wrong size for input argument #%d: string expected.\n"), "dos", 1);
25assert_checkerror("dos([""dir"", ""dir""])", refMsg);