Skip to content

Commit

Permalink
Guard against -s with stdin coming from tty
Browse files Browse the repository at this point in the history
  • Loading branch information
pzembrod committed Dec 17, 2023
1 parent ac74883 commit 9ab6d5b
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion RunCPM/abstraction_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <time.h>
#define millis() clock()/1000

#ifdef STREAMIO
#include <termios.h>
#endif

// Lua scripting support
#ifdef HASLUA
#include "lua/lua.h"
Expand Down Expand Up @@ -481,7 +485,10 @@ static void _file_failure_exit(char *argv[], char* fmt, char* filename)
{
fprintf(stderr, "%s: ", argv[0]);
fprintf(stderr, fmt, filename);
fprintf(stderr, ": %s", strerror(errno));
if (errno) {
fprintf(stderr, ": %s", strerror(errno));
}
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -509,6 +516,7 @@ static void _usage(char *argv[]) {
static void _parse_options(int argc, char *argv[]) {
int c;
int errflg = 0;
struct termios dummyTermios;
while ((c = getopt(argc, argv, ":i:o:s")) != -1) {
switch(c) {
case 'i':
Expand All @@ -527,6 +535,23 @@ static void _parse_options(int argc, char *argv[]) {
}
break;
case 's':
// fprintf(stderr, "tcgetattr() = %d\n",
// tcgetattr(0, &dummyTermios));
// fprintf(stderr, "\nerrno = %d\n", errno);
// fprintf(stderr, "ENOTTY = %d\n", ENOTTY);
// fprintf(stderr, "dummyTermios:\n"
// " c_iflag = %x\n c_oflag = %x\n"
// " c_cflag = %x\n c_lflag = %x\n",
// dummyTermios.c_iflag, dummyTermios.c_oflag,
// dummyTermios.c_cflag, dummyTermios.c_lflag);
if (0 == tcgetattr(0, &dummyTermios) ||
errno != ENOTTY) {
// fprintf(stderr, "\nerrno = %d\n", errno);
// fprintf(stderr, "ENOTTY = %d\n", ENOTTY);
_file_failure_exit(argv,
"option -s is illegal when stdin comes from %s",
"tty");
}
streamInFile = stdin;
streamOutFile = stdout;
streamInActive = TRUE;
Expand Down

0 comments on commit 9ab6d5b

Please sign in to comment.