SFML community forums

Help => Network => Topic started by: l0ud on September 01, 2009, 05:35:07 pm

Title: Problem with receiving sf::Packet
Post by: l0ud on September 01, 2009, 05:35:07 pm
Hello, I found a problem with the sf::SocketTCP::Receive(sf::Packet) function. When I send data, that is not sf::Packet, and try to recieve it with above mentioned function, the code freeze until the client disconnected.

My English is poor, so I'm not sure if anyone will understand my post. :oops: So, I'll try to explain how to reproduce the problem with simple steps:

1. Download and compile example from selectors tutorial:
http://www.sfml-dev.org/tutorials/1.5/network-selector.php

2. Start the program as server

3. (In windows) run "telnet.exe 127.0.0.1 2435"

4. Press any key

The server is no longer responding, until I close the telnet window.

It's a really easy way to "hack" the server. Using a Receive (char *Data, std::size_t MaxSize, std::size_t &SizeReceived) function works, but I'm getting only raw data, not a sf::Packet.
Title: Problem with receiving sf::Packet
Post by: Laurent on September 01, 2009, 06:21:08 pm
Of course you can receive a sf::Packet only if you sent a sf::Packet... ;)

That's because a sf::Packet has its own internal structure, it's not just raw data.
Title: Problem with receiving sf::Packet
Post by: l0ud on September 01, 2009, 06:48:23 pm
Yes, of course, but it's totally useless when every player can stop server by sending 'incomplete' packet. Is there any way to verify data before receiving as packet?
Title: Problem with receiving sf::Packet
Post by: Laurent on September 01, 2009, 07:02:53 pm
Quote
it's totally useless when every player can stop server by sending 'incomplete' packet

How would it happen? You just have to make sure that your client only sends sf::Packets.
Unless you only write the server and allow external clients to connect to it?
Title: Problem with receiving sf::Packet
Post by: l0ud on September 01, 2009, 07:56:57 pm
I'm writing the client also. But I don't have any guarantee if anyone doesn't use his own client (for example telnet.exe).
It looks like creating the web application without any protection :) Who rational will enter ' or 1=1 -- instead of his login?
Title: Problem with receiving sf::Packet
Post by: Laurent on September 01, 2009, 08:35:32 pm
Quote
But I don't have any guarantee if anyone doesn't use his own client (for example telnet.exe)

Then in this case, is it really a problem if the application freezes or behaves incorrectly?
Title: Problem with receiving sf::Packet
Post by: l0ud on September 01, 2009, 09:12:58 pm
Yes, because it's the server freeze, not the unoffical client problem. In this case, the other (normal) players can't play anymore. Server is dead, until the unoffical client disconnected.
Title: Problem with receiving sf::Packet
Post by: phear- on September 01, 2009, 09:29:11 pm
He's basically saying a malicious player can telnet into the server and crash it, which means the server is down for other non-malicious players. Exploit :)
Title: Problem with receiving sf::Packet
Post by: Laurent on September 01, 2009, 10:49:23 pm
Understood.

I'm afraid I can't help much in this case. Even if I implement something in SFML, a malicious player could still easily read the sources and adapt its client.

The only solution for you is to use raw data and implement your own secured layer over it.
Title: Problem with receiving sf::Packet
Post by: phear- on September 01, 2009, 11:51:13 pm
I think it should be up to the developer to provide his own layer of security otherwise Laurent would have to do a LOT of extra coding just to make some things secure.
Title: Problem with receiving sf::Packet
Post by: Manux on December 30, 2009, 05:37:39 am
Wouldn't setting an (optional) timeout resolve the problem?
Title: Problem with receiving sf::Packet
Post by: Laurent on December 30, 2009, 10:58:59 am
That's a solution. You may also use non-blocking sockets or threads to prevent the application from freezing.
Title: Problem with receiving sf::Packet
Post by: BoingBoing on January 10, 2010, 10:42:58 pm
Code: [Select]

char Message[128] = "";
std::size_t Received;
Client.Receive(Message, sizeof(Message), Received);

Also crashes my application. This seems to happen only when I create an SFML window, my server seems fine as a console.