From c3b948725ee9834f596b748952e5c3fc33d66020 Mon Sep 17 00:00:00 2001 From: Jakub Wilk Date: Sun, 8 May 2016 12:41:45 +0200 Subject: [PATCH] Stopped copying arguments to fixed-size buffers Don't needlessly copy command-line arguments into fixed-size buffers. Previously the program crashed if an overlong pathname was provided on the command line. Also, some systems (such as GNU Hurd) don't define MAXPATHLEN at all. --- src/include/tio/options.h | 4 ++-- src/options.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/include/tio/options.h b/src/include/tio/options.h index dc57352..0ec86bb 100644 --- a/src/include/tio/options.h +++ b/src/include/tio/options.h @@ -30,9 +30,9 @@ /* Options */ struct option_t { - char tty_device[MAXPATHLEN]; + const char *tty_device; bool log; - char log_filename[_POSIX_ARG_MAX]; + const char *log_filename; bool no_autoconnect; int output_delay; struct termios tio; diff --git a/src/options.c b/src/options.c index 83d94ec..b32601d 100644 --- a/src/options.c +++ b/src/options.c @@ -314,7 +314,7 @@ void parse_options(int argc, char *argv[]) case 'l': option.log = true; - strncpy(option.log_filename, optarg, _POSIX_ARG_MAX); + option.log_filename = optarg; break; case 'v': @@ -344,7 +344,7 @@ void parse_options(int argc, char *argv[]) /* Assume first non-option is the tty device name */ if (optind < argc) - strcpy(option.tty_device, argv[optind++]); + option.tty_device = argv[optind++]; if (strlen(option.tty_device) == 0) {