From af95c08df61287f4835efd2a92bf0edcd7667198 Mon Sep 17 00:00:00 2001 From: Yasumasa Suenaga Date: Tue, 15 Oct 2024 17:31:42 +0900 Subject: [PATCH] Resolve TTY path before opening --- tty-resizer/tty-resizer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tty-resizer/tty-resizer.c b/tty-resizer/tty-resizer.c index 3a3a4fe..84b4d15 100644 --- a/tty-resizer/tty-resizer.c +++ b/tty-resizer/tty-resizer.c @@ -19,7 +19,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -27,7 +29,7 @@ #include "common.h" -static const char *ttypath; +static char ttypath[PATH_MAX]; static ino_t tty_ino; static struct tty_resizer_bpf *skel = NULL; static struct ring_buffer *rb = NULL; @@ -119,16 +121,21 @@ static int setup_bpf(){ int main(int argc, char *argv[]){ if((argc == 3) && (strcmp(argv[1], "-v") == 0)){ libbpf_set_print(libbpf_print); - ttypath = argv[2]; + realpath(argv[2], ttypath); } else if(argc == 2){ - ttypath = argv[1]; + realpath(argv[1], ttypath); } else{ printf("Usage: %s <-v> [TTY device file]\n", argv[0]); return -100; } + if(strncmp(ttypath, "/dev/tty", 8) != 0){ + fprintf(stderr, "Not a valid TTY device: %s\n", ttypath); + return -150; + } + if((setup_tty() == 0) && (setup_bpf() == 0)){ while(true){ int ret = ring_buffer__poll(rb, -1);