Skip to content

Commit 0fe9f99

Browse files
committed
fix: Quote CL cmd in iCmd5250 for shell escaping
iCmd5250 is just a fancy wrapper around iSh, using the PASE system command. It did not do any shell escaping/quoting, so it basically only allowed calling CL commands without parameters or with only positional parameters because the parentheses would cause the shell to gack. eg. iCmd5250('wrkactjob', 'WRKACTJOB SBS(QBATCH)') basically became iSh('wrkactjob', '/QOpenSys/usr/bin/system WRKACTJOB SBS(QBATCH)') When executed, an error would be given from the shell: sh: syntax error at line 1 : `(' unexpected The proper fix is to quote the string, but that can be tricky to get right. Luckily, Python has shlex.quote to do the hard work for us. https://docs.python.org/3/library/shlex.html#shlex.quote Fixes #49
1 parent 0afda17 commit 0fe9f99

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/itoolkit/itoolkit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class iXml(iBase): IBM i XMLSERVICE raw xml input
113113
import re
114114
import time
115115

116+
from shlex import quote
116117

117118
class iBase(object): # noqa N801
118119
"""
@@ -329,7 +330,7 @@ class iCmd5250(iSh): # noqa N801
329330
"""
330331

331332
def __init__(self, ikey, icmd, iopt={}):
332-
cmd = "/QOpenSys/usr/bin/system " + icmd
333+
cmd = "/QOpenSys/usr/bin/system " + quote(icmd)
333334
super(iCmd5250, self).__init__(ikey, cmd, iopt)
334335

335336

0 commit comments

Comments
 (0)