From 710c54a254797265de3f47031b42f0a0ca4b17df Mon Sep 17 00:00:00 2001 From: Gerhard Rieger Date: Sun, 3 Mar 2019 15:08:02 +0100 Subject: [PATCH] Permit -dd; print a useful error message when single character options appear to be merged --- CHANGES | 17 ++++++++++++----- socat.c | 45 +++++++++++++++++++++++++++++++++++---------- test.sh | 24 ++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index c0c0b98..4a5480d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,5 @@ -corrections: +Corrections: Makefile.in did not specify dependencies of filan on vsnprintf_r.o and snprinterr.o Added definition of FILAN_OBJS @@ -55,7 +55,11 @@ corrections: TCP6:127.0.0.1:80 Thanks to Nicolas Fournil for reporting this issue. -porting: + Print a useful error message when single character options appear to be + merged in Socat invocation + Test: SOCCAT_OPT_HINT + +Porting: OpenSSL functions TLS1_client_method() and similar are deprecated. Socat now uses recommended TLS_client_method(). The old functions and dependend option openssl-method can still be @@ -66,7 +70,7 @@ porting: to make them better portable to systems without /bin/bash Thanks to Maya Rashish for sending a patch -testing: +Testing: test.sh: Show a warning when phase-1 (insecure phase) of a security test fails @@ -84,14 +88,17 @@ testing: ip and ss. Thanks to Ruediger Meier for reporting this problem. -git: +Git: Added missing Config/Makefile.DragonFly-2-8-2, Config/config.DragonFly-2-8-2.h Removed testcert.conf (to be generated by test.sh) -cosmetics: +Cosmetics: Simplified handling of missing termios defines. +New features: + Permit combined -d options as -dd etc. + ####################### V 1.7.3.2: corrections: diff --git a/socat.c b/socat.c index e4f38fa..0ec611e 100644 --- a/socat.c +++ b/socat.c @@ -53,6 +53,7 @@ struct { }; void socat_usage(FILE *fd); +void socat_opt_hint(FILE *fd, char a, char b); void socat_version(FILE *fd); int socat(const char *address1, const char *address2); int _socat(void); @@ -108,7 +109,8 @@ int main(int argc, const char *argv[]) { arg1 = argv+1; --argc; while (arg1[0] && (arg1[0][0] == '-')) { switch (arg1[0][1]) { - case 'V': socat_version(stdout); Exit(0); + case 'V': if (arg1[0][2]) { socat_usage(stderr); Exit(1); } + socat_version(stdout); Exit(0); #if WITH_HELP case '?': case 'h': @@ -116,9 +118,21 @@ int main(int argc, const char *argv[]) { xioopenhelp(stdout, (arg1[0][2]=='?'||arg1[0][2]=='h') ? (arg1[0][3]=='?'||arg1[0][3]=='h') ? 2 : 1 : 0); Exit(0); #endif /* WITH_HELP */ - case 'd': diag_set('d', NULL); break; + case 'd': + a = *arg1+1; + while (*a) { + if (*a == 'd') { + diag_set('d', NULL); + } else { + socat_usage(stderr); + Exit(1); + } + ++a; + } + break; #if WITH_FILAN - case 'D': socat_opts.debug = true; break; + case 'D': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); } + socat_opts.debug = true; break; #endif case 'l': switch (arg1[0][2]) { @@ -156,8 +170,10 @@ int main(int argc, const char *argv[]) { break; } break; - case 'v': socat_opts.verbose = true; break; - case 'x': socat_opts.verbhex = true; break; + case 'v': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); } + socat_opts.verbose = true; break; + case 'x': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); } + socat_opts.verbhex = true; break; case 'b': if (arg1[0][2]) { a = *arg1+2; } else { @@ -169,7 +185,7 @@ int main(int argc, const char *argv[]) { } socat_opts.bufsiz = strtoul(a, (char **)&a, 0); break; - case 's': + case 's': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); } diag_set_int('e', E_FATAL); break; case 't': if (arg1[0][2]) { a = *arg1+2; @@ -199,9 +215,12 @@ int main(int argc, const char *argv[]) { socat_opts.total_timeout.tv_usec = (rto-socat_opts.total_timeout.tv_sec) * 1000000; break; - case 'u': socat_opts.lefttoright = true; break; - case 'U': socat_opts.righttoleft = true; break; - case 'g': xioopts_ignoregroups = true; break; + case 'u': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); } + socat_opts.lefttoright = true; break; + case 'U': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); } + socat_opts.righttoleft = true; break; + case 'g': if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); } + xioopts_ignoregroups = true; break; case 'L': if (socat_opts.lock.lockfile) Error("only one -L and -W option allowed"); if (arg1[0][2]) { @@ -236,6 +255,7 @@ int main(int argc, const char *argv[]) { #if WITH_IP6 case '6': #endif + if (arg1[0][2]) { socat_opt_hint(stderr, arg1[0][1], arg1[0][2]); Exit(1); } xioopts.default_ip = arg1[0][1]; xioopts.preferred_ip = arg1[0][1]; break; @@ -333,7 +353,7 @@ void socat_usage(FILE *fd) { fputs(" -hh like -h, plus a list of all common address option names\n", fd); fputs(" -hhh like -hh, plus a list of all available address option names\n", fd); #endif /* WITH_HELP */ - fputs(" -d increase verbosity (use up to 4 times; 2 are recommended)\n", fd); + fputs(" -d[ddd] increase verbosity (use up to 4 times; 2 are recommended)\n", fd); #if WITH_FILAN fputs(" -D analyze file descriptors before loop\n", fd); #endif @@ -363,6 +383,11 @@ void socat_usage(FILE *fd) { #endif } +void socat_opt_hint(FILE *fd, char a, char b) { + fprintf(fd, "Do not merge single character options, i.e. use \"-%c -%c\" instead of \"-%c%c\"\n", + a, b, a, b); +} + void socat_version(FILE *fd) { struct utsname ubuf; diff --git a/test.sh b/test.sh index d304912..984265a 100755 --- a/test.sh +++ b/test.sh @@ -12950,6 +12950,30 @@ PORT=$((PORT+1)) N=$((N+1)) +NAME=SOCAT_OPT_HINT +case "$TESTS" in +*%$N%*|*%socat%*|*%$NAME%*) +TEST="$NAME: check if merging single character options is rejected" +if ! eval $NUMCOND; then :; else +te="$td/test$N.stderr" +CMD0="$TRACE $SOCAT $opts -vx FILE:/dev/null ECHO" +printf "test $F_n $TEST... " $N +$CMD0 >/dev/null 2>"${te}0" +rc0=$? +if [ "$rc0" = "1" ]; then + $PRINTF "$OK\n" + numOK=$((numOK+1)) +else + $PRINTF "$FAILED\n" + echo "$CMD0" >&2 + numFAIL=$((numFAIL+1)) + listFAIL="$listFAIL $N" +fi +fi ;; # NUMCOND +esac +N=$((N+1)) + + ################################################################################## #================================================================================= # here come tests that might affect your systems integrity. Put normal tests