/* Each command is the first character of a line. */
saveptr = NULL;
line = strtok_r(buffer, "\n", &saveptr); while (line) { if (*line != '#' && strlen(line) != 1) {
fprintf(stderr, "# ERROR: Unknown string\n"); return 1;
} switch (*line) { case'#': /* Skips shebang and comments. */ break; case'+': /* Increments and prints the number. */
number++;
printf("%lld\n", number); break; case'?': /* Reads integer from stdin. */
fprintf(stderr, "> Enter new number: \n"); if (scanf("%lld", &number) != 1) {
fprintf(stderr, "# WARNING: Failed to read number from stdin\n");
} break; default:
fprintf(stderr, "# ERROR: Unknown character '%c'\n",
*line); return 1;
}
line = strtok_r(NULL, "\n", &saveptr);
} return 0;
}
/* * We pass a valid argv and envp to the kernel to emulate a native * script execution. We must use the script file descriptor instead of * the script path name to avoid race conditions.
*/
err = sys_execveat(fileno(script), "", script_argv, envp,
AT_EMPTY_PATH | AT_EXECVE_CHECK); if (err && restrict_stream) {
perror("ERROR: Script execution check"); return 1;
}
secbits = prctl(PR_GET_SECUREBITS); if (secbits == -1) { /* * This should never happen, except with a buggy seccomp * filter.
*/
perror("ERROR: Failed to get securebits"); return 1;
}
/* Checks that only one argument is used, or read stdin. */
arg_nb = !!cmd + !!interpret_stdin; if (arg_nb == 0 && argc == 2) {
script_name = argv[1];
} elseif (arg_nb != 1) {
print_usage(argv[0]); return 1;
}
if (cmd) { /* * Other kind of interactive interpretations should be denied * as well (e.g. CLI arguments passing script snippets, * environment variables interpreted as script). However, any * way to pass script files should only be restricted according * to restrict_file.
*/ if (deny_interactive) {
fprintf(stderr, "ERROR: Interactive interpretation denied.\n"); return 1;
}
return interpret_buffer(cmd, strlen(cmd));
}
if (interpret_stdin && !script_name) {
script_file = stdin; /* * As for any execve(2) call, this path may be logged by the * kernel.
*/
script_name = "/proc/self/fd/0"; /* * When stdin is used, it can point to a regular file or a * pipe. Restrict stdin execution according to * SECBIT_EXEC_DENY_INTERACTIVE but always allow executable * files (which are not considered as interactive inputs).
*/ return interpret_stream(script_file, script_name, envp,
deny_interactive);
} elseif (script_name && !interpret_stdin) { /* * In this sample, we don't pass any argument to scripts, but * otherwise we would have to forge an argv with such * arguments.
*/
script_file = fopen(script_name, "r"); if (!script_file) {
perror("ERROR: Failed to open script"); return 1;
} /* * Restricts file execution according to * SECBIT_EXEC_RESTRICT_FILE.
*/ return interpret_stream(script_file, script_name, envp,
restrict_file);
}
print_usage(argv[0]); return 1;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.0 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.