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

String Unpack Crash #12

Open
RLovelett opened this issue Dec 26, 2013 · 4 comments
Open

String Unpack Crash #12

RLovelett opened this issue Dec 26, 2013 · 4 comments

Comments

@RLovelett
Copy link

After successfully connecting to my VPN, occasionally the connection will die with the following error: 'x' outside of string in unpack at ./jvpn.pl line 556..

Ultimately, it is not a show stopper issue because I can always restart the connection. It is just a nuisance.

@RLovelett
Copy link
Author

In an effort to debug this further I have patched jvpn.pl to look like this:

diff --git a/jvpn.pl b/jvpn.pl
index 95d951f..547beb9 100755
--- a/jvpn.pl
+++ b/jvpn.pl
@@ -553,10 +553,23 @@ if($mode eq "ncsvc") {
                my $now = time - $start_t;
                # printing RX/TX. This packet also contains encription type,
                # compression and transport info, but length seems to be variable
-               printf("Duration: %02d:%02d:%02d  Sent: %s\tReceived: %s", 
-                       int($now / 3600), int(($now % 3600) / 60), int($now % 60),
-                       format_bytes(unpack('x[78]N',$data)), format_bytes(unpack('x[68]N',$data)));
-               sleep(1);
+               eval {
+                       my $hours = int($now / 3600);
+                       my $minutes = int(($now % 3600) / 60);
+                       my $seconds = int($now % 60);
+                       my $txUnpack = unpack('x[78]N', $data);
+                       my $rxUnpack = unpack('x[68]N', $data);
+                       my $txBytes = format_bytes($txUnpack);
+                       my $rxBytes = format_bytes($rxUnpack);
+                       printf("Duration: %02d:%02d:%02d  Sent: %s\tReceived: %s",
+                               $hours, $minutes, $seconds, $txBytes, $rxBytes);
+                       sleep(1);
+               } or do {
+                       my $e = $@;
+                       print("Something went wrong: $e\n");
+                       hdump($data);
+                       print("$data\n");
+               }
        }

This now outputs this when it encounters an error (line 560 is my $txUnpack = unpack('x[78]N', $data);):

Something went wrong: 'x' outside of string in unpack at ./jvpn.pl line 560.

0x00000000 (00000)   00000000 0000007e 01000000 01000000   .......~........
0x00000010 (00016)   00000010 00c80000 000a0001 00000004   ................
0x00000020 (00032)   00000000 00000000 0000006d 01000000   ...........m....
0x00000030 (00048)   01000000 00000010 00c80000 000a0001   ................
0x00000040 (00064)   00000004 00000000                     ........
~����
��m����

I am no Perl ninja so I am not entirely sure what unpack is trying to do. Still trying to find a permanent patch for this.

@Line-Noise
Copy link

I'm seeing this error too. Usually when the VPN tunnel is dropped after the 24 hour connection time limit that is set on our VPN.

I, too, am a bit vague on unpack and pack but I think the x[78]N means that it skips over 78 bytes in $data and then reads the next 32 bits as a bigendian unsigned long. As you can see from your debug output $data is only 72 bytes long which is less than the 78 bytes x is trying to skip, hence the 'x' outside of string error.

I suspect that the solution when this error occurs is to drop the connection and reconnect. But I can't see a tidy way to do that apart from execing the whole script again (which is not really very tidy!).

@RLovelett
Copy link
Author

@Line-Noise I usually get this within 45 minutes of the connection starting. Does not rule out it being some sort of connection drop message. Just that the timing is different. Oddly enough usually within a few minutes of receiving this 'bad' packet, I call it that for lack of better understanding, the connection resumes and continues on. It is definitely a weird situation.

@samm-git
Copy link
Owner

samm-git commented Feb 7, 2014

I like @RLovelett idea and i think i will import it. There is no any documentation of the format of the packets, so everything possible. Another suggestion is to try to use ncsvc mode, this could help.

irobertson added a commit to irobertson/jvpn that referenced this issue Nov 17, 2016
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

No branches or pull requests

3 participants