#include "sg_socket.hxx"
bool SGSocket::init = false;
+using std::string;
SGSocket::SGSocket( const string& host, const string& port_,
const string& style ) :
return false;
}
- if (sock.bind( "", port ) < 0)
+ if (sock.bind( hostname.c_str(), port ) < 0)
{
SG_LOG( SG_IO, SG_ALERT,
"Error: bind() failed in make_server_socket()" );
int i;
for ( i = 0; i < save_len && save_buf[i] != '\n'; ++i )
;
- if ( save_buf[i] == '\n' ) {
+ if (( i < save_len ) && ( save_buf[i] == '\n' )) {
result = i + 1;
} else {
// no end of line yet
// we found an end of line
+ // check buffer size
+ int copy_length = result;
+ if (copy_length >= length) {
+ SG_LOG( SG_IO, SG_ALERT,
+ "Alert: readline() has line exceeding the buffer size." );
+ copy_length = length-1;
+ }
// copy to external buffer
- strncpy( buf, save_buf, result );
- buf[result] = '\0';
+ strncpy( buf, save_buf, copy_length );
+ buf[copy_length] = '\0';
// shift save buffer
//memmove( save_buf+, save_buf+, ? );