shc icon indicating copy to clipboard operation
shc copied to clipboard

Different results from a very short shell script and shc compiled binary

Open hanyunfan opened this issue 6 years ago • 6 comments

[root@sys1 shc]# ./test_prograss_bar.sh Start run: /BG: 22 [root@sys1 shc]# shc -f test_prograss_bar.sh -o test_prograss_bar.bin shc: WARNING!! Scripts of length near to (or higher than) the current System limit on "maximum size of arguments to EXEC", could comprise its binary execution. In the current System the call sysconf(_SC_ARG_MAX) returns -1 bytes and your script "test_prograss_bar.sh" is 432 bytes length. [root@deepdell shc]# ./test_prograss_bar.bin Start run: /./test_prograss_bar.bin: line 25: wait: %1: no such job BG: 127 [root@sys1 shc]# cat ./test_prograss_bar.sh #!/bin/bash

cmd="sleep 5; exit 22" #runs Good LOGFILE="/tmp/tmp.tmp"

bar(){

printf "running command:\n $1:\nResults:\n" &>>$LOGFILE sh -c "$1" &>>$LOGFILE & pid=$! spin[0]="-" spin[1]="\" spin[2]="|" spin[3]="/"

printf "$2: ${spin[0]}" while kill -0 $pid 2>/dev/null do for i in "${spin[@]}" do echo -ne "\b$i" sleep 0.1 done done

wait %1 #judge the output printf "BG: $?\n"

}

bar "$cmd" "Start run" [root@sys1 shc]#

I am running it under RHEL 7.4 with the zip file downloaded from git hub, the git clone one reports error after compiled aclocal-1.15.1:

[root@sys1 shc]# make CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /backup/frank/shc/shc/config/missing aclocal-1.15 -I m4 Can't locate Automake/Config.pm in @INC (@INC contains: /usr/local/share/automake-1.15 /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /backup/frank/shc/automake-1.15.1/bin/aclocal-1.15 line 37. BEGIN failed--compilation aborted at /backup/frank/shc/automake-1.15.1/bin/aclocal-1.15 line 37. make: *** [aclocal.m4] Error 2

hanyunfan avatar May 15 '18 14:05 hanyunfan

git clone is working. but the git version has the same output, which is different with original bash script. Any workaround?

hanyunfan avatar May 15 '18 14:05 hanyunfan

Can you check with the current version and eventually with the H flag

intika avatar Nov 12 '18 19:11 intika

Still no luck. Details as below:

[root@deepdell3 src]# cat test_prograss_bar.sh #!/bin/bash

cmd="sleep 5; exit 22" #runs Good LOGFILE="/tmp/tmp.tmp"

bar(){

printf "running command:\n $1:\nResults:\n" &>>$LOGFILE
sh -c "$1" &>>$LOGFILE &
pid=$!
spin[0]="-"
spin[1]="\\"
spin[2]="|"
spin[3]="/"

printf "$2: ${spin[0]}"
while kill -0 $pid 2>/dev/null
    do
        for i in "${spin[@]}"
            do
                echo -ne "\b$i"
                sleep 0.1
                done
                done

                wait %1

#judge the output printf "BG: $?\n"

}

bar "$cmd" "Start run"

[root@deepdell3 src]# ./shc -H -s -f test_prograss_bar.sh -o test.bin shc: WARNING!! Scripts of length near to (or higher than) the current System limit on "maximum size of arguments to EXEC", could comprise its binary execution. In the current System the call sysconf(_SC_ARG_MAX) returns -1 bytes and your script "test_prograss_bar.sh" is 602 bytes length. [root@deepdell3 src]# ./test.bin Operation not permitted Killed

hanyunfan avatar Nov 19 '18 21:11 hanyunfan

shc doesn't check sysconfig(_SC_ARG_MAX) returns -1 or sets errno, which it does if it gets an unknown argument. I can try to look into writing a fix for these.

@hanyunfan can you post the outputs of

getconf ARG_MAX
getconf -a | grep -i arg
getconf -a | grep LONG

please :)

catb0t avatar Nov 20 '18 00:11 catb0t

thanks for the reply. Here is the results:

[root@deepdell3 src]# getconf ARG_MAX 4611686018427387903 [root@deepdell3 src]# getconf -a | grep -i arg ARG_MAX 4611686018427387903 NL_ARGMAX 4096 _POSIX_ARG_MAX 4611686018427387903 LFS64_CFLAGS -D_LARGEFILE64_SOURCE LFS64_LINTFLAGS -D_LARGEFILE64_SOURCE XBS5_ILP32_OFFBIG_CFLAGS -m32 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 POSIX_V6_ILP32_OFFBIG_CFLAGS -m32 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 POSIX_V7_ILP32_OFFBIG_CFLAGS -m32 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64

hanyunfan avatar Nov 20 '18 16:11 hanyunfan

[root@deepdell3 src]# getconf -a | grep LONG LONG_BIT 64 ULONG_MAX 18446744073709551615

hanyunfan avatar Nov 20 '18 16:11 hanyunfan