The pointer and memory allocation/deallocation make C/C++ powerful, but they are not easy to handle for an inexperienced programmer. The inappropriate handling of the pointer and memory can lead to buffer overflow. We have noticed that a very high percentage of programs that crash suffer from the mishandling of the string.
Ch recognizes this shortcoming and has a built-in string type with automatic memory management to resolve this problem. It can work seamlessly with the type char* and char []. Users are encouraged to use this feature for rapid application development without concerns for memory handling and pointers. Furthermore, Ch checks array bounds automatically to avoid memory corruption.
Safe Ch is introduced to address the security concerns for C-based applets to run across the Internet or as a restricted shell. Safe Ch disables the use of C pointer and reduces the potential security risk while taking advantage of pointers in other applications such as real-time control of machinery and data acquisition. Safe Ch has a sandbox and limits a malicious applet from gaining privilege to take full control of the computer.
Program chs is safe Ch shell. If the -S flag is present when the Ch language environment is invoked as ch -S , the Ch shell is a safe shell. The macro _SCH_ is predefined with value 1 for a safe shell. The execution environments of a safe shell are more controlled than those of the regular shell and restricted shell. Ch -S and Ch run similarly, except that the following features are disabled in safe shell:
system()
_path, _fpath, _ipath,
_user, _home, _cwd, _shell, _host as lvalue.
To the safe shell user,
these system variables have value of NULL. To test setup,
you may print the values of these system variables
inside startup file .chsrc
in Unix and _chsrc in Windows
in the user's home directory.
#!/bin/ch -S
restrict void funct(void) {
printf("This function cannot be called by Safe Ch program.\n");
}
funct(); // Eerror: call restricted functions
The following restricted functions cannot be called by
safe Ch programs:
accept(),
chdir(),
chown(),
chroot(),
creat(),
execl(),
execv(),
execle(),
execve(),
execlp(),
execvp(),
fchdir(),
fchown(),
fchroot(),
fdopen(),
fopen(),
fstat(),
gethostname(),
kill(),
lchown(),
link(),
lstat(),
mkdir(),
pipe(),
popen(),
remove(),
rename(),
rmdir(),
socket(),
socketpair(),
stat(),
system(),
unlink().
When a command to be executed is found to be a Ch program, the safe shell invokes ch -S to execute it. If a Ch program is invoked with shell identification #!/bin/ch without option -S, the safe shell invokes ch to execute it. Thus, it is possible to provide to the end-user Ch programs that have access to the full power of the regular shell, while imposing a limited number of commands; this scheme assumes that the end-user does not have write and execute permissions in a directory containing commands. Therefore, the writer of the .chsrc has complete control over user actions, by performing guaranteed setup actions and leaving the user in an appropriate directory (probably not the login directory). A default directory CHHOME/sbin has been setup for putting binary and Ch commands, respectively, that can be safely invoked by safe shell. Applications of safe Ch are illustrated by Ch applet-based network computing.