fix: Quote CL cmd in iCmd5250 for shell escaping#50
Merged
Conversation
Member
Author
|
@ranga543 Can you please test this? I was able to verify with this script: from itoolkit import *
from itoolkit.transport import DirectTransport
itransport = DirectTransport()
itool = iToolKit()
itool.add(iCmd('aspgroup_cmd', 'SETASPGRP ASPGRP(TEST)'))
itool.add(iCmd5250('dspjob', 'DSPJOB'))
itool.call(itransport)
print(itool.dict_out('aspgroup_cmd'))
for line in itool.dict_out('dspjob')['dspjob'].split('\n'):
if 'ASP' not in line:
continue
print(line)Note that you must use |
|
@kadler I copied your code and tried it and that seems to be working. |
|
@kadler Is there a way to capture error from |
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
0fe9f99 to
5b8493d
Compare
|
@kadler any ideas ? |
Member
Author
|
I'm not sure exactly what you're asking for, but in general error handling in XMLSERVICE is an after thought and there's not much that itoolkit can do about it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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