Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tunnel parsing exception handling. #550

Merged
merged 1 commit into from
Dec 14, 2022
Merged

Conversation

jshort
Copy link
Collaborator

@jshort jshort commented Dec 2, 2022

Rather than using STFATAL and exiting, bubble up tunnel parsing exception to main and display the responsible option arg and print help menu so the user need not dig into /tmp/etclient-* to determine why et aborted.

Fixes #491

Testing:

 ❯ ./et -p abc localhost:8080 --macserver                                                                                                                                                                                     14:57:23  12.02.22
Exception: Argument ‘abc’ failed to parse


Remote shell for the busy and impatient
Usage:
  et [OPTION...] [user@]host[:port]

  Note that 'host' can be a hostname or ipv4 address with or without a port
  or an ipv6 address. If the ipv6 address is abbreviated with :: then it must
  be specified without a port (use -p,--port).

  -h, --help                 Print help
      --version              Print version
  -u, --username             Username
      --host arg             Remote host name
  -p, --port arg             Remote machine etserver port (default: 2022)
  -c, --command arg          Run command on connect
      --terminal-path arg    Path to etterminal on server side. Use if
                             etterminal is not on the system path.
  -t, --tunnel arg           Tunnel: Array of source:destination ports or
                             srcStart-srcEnd:dstStart-dstEnd (inclusive) port
                             ranges (e.g. 10080:80,10443:443,
                             10090-10092:8000-8002)
  -r, --reversetunnel arg    Reverse Tunnel: Array of source:destination
                             ports or srcStart-srcEnd:dstStart-dstEnd (inclusive)
                             port ranges
      --jumphost arg         jumphost between localhost and destination
      --jport arg            Jumphost machine port (default: 2022)
  -x, --kill-other-sessions  kill all old sessions belonging to the user
      --macserver            Set when connecting to an macOS server.  Sets
                             --terminal-path=/usr/local/bin/etterminal
  -v, --verbose arg          Enable verbose logging (default: 0)
  -k, --keepalive arg        Client keepalive duration in seconds
      --logtostdout          Write log to stdout
      --silent               Disable logging
  -N, --no-terminal          Do not create a terminal
  -f, --forward-ssh-agent    Forward ssh-agent socket
      --ssh-socket arg       The ssh-agent socket to forward
      --telemetry            Allow et to anonymously send errors to guide
                             future improvements (default: true)
      --serverfifo arg       If set, communicate to etserver on the matching
                             fifo name (default: )
      --ssh-option arg       Options to pass down to `ssh -o`


 ↵ 1  ⚙  jwshort@MAC-DESKTOP  ~/gitworkspaces/EternalTerminal/build   master ● ⍟2 
 ❯ ./et -t 6010 localhost:8080 --macserver                                                                                                                                                                                    14:57:34  12.02.22
Exception: Invalid tunnel argument: 6010


Remote shell for the busy and impatient
Usage:
  et [OPTION...] [user@]host[:port]

  Note that 'host' can be a hostname or ipv4 address with or without a port
  or an ipv6 address. If the ipv6 address is abbreviated with :: then it must
  be specified without a port (use -p,--port).

  -h, --help                 Print help
      --version              Print version
  -u, --username             Username
      --host arg             Remote host name
  -p, --port arg             Remote machine etserver port (default: 2022)
  -c, --command arg          Run command on connect
      --terminal-path arg    Path to etterminal on server side. Use if
                             etterminal is not on the system path.
  -t, --tunnel arg           Tunnel: Array of source:destination ports or
                             srcStart-srcEnd:dstStart-dstEnd (inclusive) port
                             ranges (e.g. 10080:80,10443:443,
                             10090-10092:8000-8002)
  -r, --reversetunnel arg    Reverse Tunnel: Array of source:destination
                             ports or srcStart-srcEnd:dstStart-dstEnd (inclusive)
                             port ranges
      --jumphost arg         jumphost between localhost and destination
      --jport arg            Jumphost machine port (default: 2022)
  -x, --kill-other-sessions  kill all old sessions belonging to the user
      --macserver            Set when connecting to an macOS server.  Sets
                             --terminal-path=/usr/local/bin/etterminal
  -v, --verbose arg          Enable verbose logging (default: 0)
  -k, --keepalive arg        Client keepalive duration in seconds
      --logtostdout          Write log to stdout
      --silent               Disable logging
  -N, --no-terminal          Do not create a terminal
  -f, --forward-ssh-agent    Forward ssh-agent socket
      --ssh-socket arg       The ssh-agent socket to forward
      --telemetry            Allow et to anonymously send errors to guide
                             future improvements (default: true)
      --serverfifo arg       If set, communicate to etserver on the matching
                             fifo name (default: )
      --ssh-option arg       Options to pass down to `ssh -o`


 ↵ 1  ⚙  jwshort@MAC-DESKTOP  ~/gitworkspaces/EternalTerminal/build   master ● ⍟2 
 ❯ ./et -t 6010:6000 localhost:8080 --macserver                                                                                                                                                                               14:57:55  12.02.22

####################################################################################
Welcome to your MacOS Desktop.
####################################################################################

@jshort
Copy link
Collaborator Author

jshort commented Dec 3, 2022

Let me get some coverage for this. et::HandleTerminate is interfering with Catch2's REQUIRE_THROWS(...) but I should be able to work around it.

@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2022

Codecov Report

Base: 70.75% // Head: 73.17% // Increases project coverage by +2.41% 🎉

Coverage data is based on head (aff4ad7) compared to base (91099f6).
Patch coverage: 95.38% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #550      +/-   ##
==========================================
+ Coverage   70.75%   73.17%   +2.41%     
==========================================
  Files          49       51       +2     
  Lines        3074     3094      +20     
==========================================
+ Hits         2175     2264      +89     
+ Misses        899      830      -69     
Impacted Files Coverage Δ
src/terminal/TerminalClient.cpp 49.75% <ø> (+8.52%) ⬆️
src/base/TunnelUtils.cpp 93.18% <93.18%> (ø)
src/base/TunnelUtils.hpp 100.00% <100.00%> (ø)
test/TerminalTest.cpp 93.57% <100.00%> (+0.61%) ⬆️
src/terminal/TerminalServer.cpp 72.69% <0.00%> (-0.41%) ⬇️
src/base/Connection.cpp 88.69% <0.00%> (ø)
src/terminal/UserTerminalHandler.cpp 71.26% <0.00%> (+1.26%) ⬆️
src/base/SocketHandler.cpp 63.63% <0.00%> (+1.29%) ⬆️
src/terminal/UserJumphostHandler.cpp 64.80% <0.00%> (+3.19%) ⬆️
src/base/ClientConnection.cpp 77.27% <0.00%> (+3.63%) ⬆️
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jshort
Copy link
Collaborator Author

jshort commented Dec 13, 2022

Ehhh, I want to move the tunnel parse logic and exception to a separate header/impl to get it out of TerminalClient.(hpp|cpp).

@jshort jshort force-pushed the tunnel_parse branch 3 times, most recently from 4e16866 to aff4ad7 Compare December 14, 2022 18:39
Rather than using STFATAL and exiting, bubble up tunnel parsing
exception to main and display the responsible option arg and print help
menu so the user need not dig into /tmp/etclient-* to determine why et
aborted.

Fixes MisterTea#491
@jshort jshort merged commit 10dd371 into MisterTea:master Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Out of bounds array access on caused by unexpected user input to --tunnel
2 participants