@@ -16,22 +16,25 @@ class clsSock {
1616
1717 void send (const string &msg) {
1818 short msgSize = msg.size ();
19- SSL_write (ssl, &msgSize, sizeof (msgSize));
20- SSL_write (ssl, msg.c_str (), msgSize);
19+ if (SSL_write (ssl, &msgSize, sizeof (msgSize)) <= 0 )
20+ throw runtime_error (" Error writing message size to SSL." );
21+ if (SSL_write (ssl, msg.c_str (), msgSize) <= 0 )
22+ throw runtime_error (" Error writing message body to SSL." );
2123 }
2224 string recv () {
2325 try {
2426 short msgSize;
2527 if (SSL_read (ssl, (char *)&msgSize, sizeof (msgSize)) <= 0 )
26- throw runtime_error (" [!] Error reading message size." );
28+ throw runtime_error (" [!] Error reading message size from SSL ." );
2729 string res;
2830 char buffer[1024 ];
2931 while (msgSize) {
3032 memset (buffer, 0 , sizeof (buffer));
3133 int bytesRead =
3234 SSL_read (ssl, buffer, min ((short )sizeof (buffer), msgSize));
3335 if (bytesRead <= 0 )
34- throw runtime_error (" [!] Error reading message body" );
36+ throw runtime_error (
37+ " [!] Error reading message body from SSL." );
3538 msgSize -= bytesRead;
3639 res.append (buffer);
3740 }
@@ -49,21 +52,27 @@ class clsSock {
4952 throw runtime_error (" [!] Failed to open the file for reading." );
5053 input.seekg (0 , ios::end);
5154 long fileSize = input.tellg ();
55+ if (fileSize < 0 )
56+ throw runtime_error (" [!] Failed to get the file size." );
5257 input.seekg (0 , ios::beg);
53- SSL_write (ssl, &fileSize, sizeof (fileSize));
58+ if (SSL_write (ssl, &fileSize, sizeof (fileSize)) <= 0 )
59+ throw runtime_error (
60+ " [!] Error writing file content size to SSL." );
5461 char buffer[1024 ];
5562 long bytesLeft = fileSize;
5663 while (bytesLeft) {
5764 short bytesToSend = min (bytesLeft, (long )sizeof (buffer));
5865 input.read (buffer, bytesToSend);
59- SSL_write (ssl, buffer, bytesToSend);
66+ if (SSL_write (ssl, buffer, bytesToSend) <= 0 )
67+ throw runtime_error (
68+ " [!] Error writing file content to SSL." );
6069 bytesLeft -= bytesToSend;
6170 memset (buffer, 0 , sizeof (buffer));
6271 if (callback) callback (fileSize - bytesLeft, fileSize);
6372 }
6473 input.close ();
6574 } catch (const runtime_error &e) {
66- cerr << e. what () << endl ;
75+ throw ;
6776 }
6877 }
6978 void recvFile (const string &path,
0 commit comments