in reply to Re^3: Embed perl problem
in thread Embed perl problem

I think i found the problem. when i run this code its ok:

//test.c eval_pv("code normal");

but when i use this , program stops:

//test.c void decode(char * block, char *key, int len) { //decode action goes here } char block[] = "encoded perl code like {0xaa,0xb9,0xb5}"; decode(block,"key",len); eval_pv(block);

also when i print the decoded string for debug purpose its same as original code.

Replies are listed 'Best First'.
Re^5: Embed perl problem
by bliako (Abbot) on Feb 02, 2019 at 19:23 UTC

    It smells like a missing string terminator, the NULL at the end of your block. printf() might be a lot less sensitive than eval_pv() when feeding it with a football-field worth of core. The initialiser char block[]="abc"; puts a NULL at the end whereas char block[] = {0xaa,0xbb,0xcc} doesn't... and do not attempt to add one as it's a const. Long story short, add a 0x0 after 0xcc and make sure your decode() keeps it there.

      no chance. seems problem comes from calling system("ls -a"); in my code. when i using ptrace in c together with system calls in my perl code program stop running with + Stopped message at the end of program.

        I think about an alternative way, if i could detect when i my program run like this , problem can be solved almost:

        parent program

        vs

        program

        how can i detect when my program run by parent in perl?

        Any idea?