feat(chvt): use custom implementation instead of system()

Calling system() is vulnerable and shouldn't be used.
This commit is contained in:
grialion
2024-08-06 17:11:18 +02:00
parent eeba4a5f39
commit e745b27a68
4 changed files with 53 additions and 9 deletions

View File

@@ -4,22 +4,23 @@
#include <sys/types.h>
#include <unistd.h>
#include <chvt.h>
#include <config.h>
#include <sessions.h>
#include <ui.h>
#include <users.h>
void chvt(char *arg) {
size_t bsize = snprintf(NULL, 0, "chvt %s", arg) + 1;
char *buf = malloc(bsize);
snprintf(buf, bsize, "chvt %s", arg);
system(buf);
free(buf);
int chvt_char(char c) {
int i = c - '0';
if (i >= 0 && i <= 9) {
return chvt(i);
}
return -1;
}
int main(int argc, char *argv[]) {
if (argc == 2)
chvt(argv[1]);
chvt_char(argv[1][0]);
struct config *config = parse_config("/etc/lidm.ini");
if (config == NULL) {