Closed yilmazdurmaz closed 2 years ago
will look into it
I had time to dive into the code a bit.
I could not follow pointers and sizes, yet I came to a point where a simple comparison change, namely from <
to <=
, fixes the issue.
assert(strlen(c)+strlen(f->s) <= n);
assert(strlen(c)+strlen(p) <= n);
In connection to my other issue, #34 , if the additions of quotes are good to go, then we need extra n+=1
in two places.
{ strcat(c, " \""); n += 1;
assert(strlen(c)+strlen(f->s) <= n);
strcat(c, f->s);
strcat(c, "\""); n += 1;
}
Following are results after the above change (with quotes)
$ cobra -comments -terse test.py
: !$COBRA
lengths: 31 0 31
content: /home/ubuntu/Cobra/rules/../bin
: !$FLAGS
lengths: 0 0 14
content:
sh: 1: -terse: not found
: !$ARGS
lengths: 2 7 9 (before adding file name and closing quote)
lengths:10 0 10
content: "test.py"
sh: 1: test.py: not found
Please check if these changes are suitable to include in your codebase.
YILMAZ
Please be cautious about my above message.
I see that using this n
, you are allocating a memory block before reaching the code I changed, and I admit I don't understand memory allocations.
c = (char *) emalloc((n+1)*sizeof(char), 69); // single core
my changes do work with a single file and relatively short names, but I guess with multiple files opened it will cause memory problems. (my shell script finds files and processes them one by one)
You are the expert, so I leave the rest in your hands. YILMAZ
I double checked, and agree with your assessment -- will update a corrected version with the update to version 3.8, tpday
Executing commands on host while in Cobra is nice
! c execute command(s) c in a background shell
But I have found this issue while checking for another one. So far I could run many shell commands with
!
and had no issue other than trying to use $COBRA and $ARGS.I have seen there is an old post from 2019. Since you marked it as solved and I could not relate that to these two, I opened this new issue.
My other issue, #34, might be irrelevant but also might be directly caused by this one, So you may want to check them together.
Thanks YILMAZ