Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Incompatible packets with sf::Packet blocking program  (Read 2849 times)

0 Members and 1 Guest are viewing this topic.

ScuroGuardiano

  • Newbie
  • *
  • Posts: 2
    • View Profile
Incompatible packets with sf::Packet blocking program
« on: October 25, 2016, 12:49:17 am »
Hi
I have a problem with receiving packets to sf::Packet. It's very comfortable to use it, but when one of clients send incompatible packet (for example I type server address with port in browser) server get stopped until I close incompatible client. How I can make ignoring incompatible packets with sf::Packet? Code:
//loop code
if( selektor.isReady( Clients[ i ] ) )
{
    sf::Packet temp;
    Clients[ i ]->receive( temp ); //Here program stops when I send incompatible packet
}
//loop code

PS. Sorry for my bad english, in polish schools they don't teach good :/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Incompatible packets with sf::Packet blocking program
« Reply #1 on: October 25, 2016, 09:20:17 am »
You can't. sf::Packet expects the size to be sent first; if it receives random data instead it can't know, and it'll wait until it has received the said number of bytes (which can be huge since it is random).

It's your job to ensure that sf::Packet only receives compatible data. I know it's not ideal, sf::Packet suffers from many design issues and it will hopefully be improved in the future, but that will not happen before SFML 3.
Laurent Gomila - SFML developer

ScuroGuardiano

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Incompatible packets with sf::Packet blocking program
« Reply #2 on: October 25, 2016, 04:00:14 pm »
Ok, thanks for reply.

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Incompatible packets with sf::Packet blocking program
« Reply #3 on: October 25, 2016, 10:03:56 pm »
It's your job to ensure that sf::Packet only receives compatible data. I know it's not ideal, sf::Packet suffers from many design issues and it will hopefully be improved in the future, but that will not happen before SFML 3.

So Laurent, while we wait, you recommend better to use other posibles alternatives like SFNUL from binary1248?
I would like a spanish/latin community...
Problems building for Android? Look here

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Incompatible packets with sf::Packet blocking program
« Reply #4 on: October 25, 2016, 10:24:47 pm »
So Laurent, while we wait, you recommend better to use other posibles alternatives like SFNUL from binary1248?
That won't help with the problem here either. There is no library in the world that can automatically protect against malicious attackers without knowledge of the application itself, and that knowledge comes from the developer, who has to write the checks themselves. There is a reason why network programmers should live by the phrase "never rely on incoming data being sane".

If Laurent was referring to the other known issues with sf::Packet as well, then "maybe".
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

 

anything