mirror of
				https://github.com/rofafor/vdr-plugin-iptv.git
				synced 2023-10-10 11:37:03 +00:00 
			
		
		
		
	Robustify network protocols with more error checking.
This commit is contained in:
		| @@ -3,7 +3,7 @@ | ||||
|  * | ||||
|  * See the README file for copyright information and how to reach the author. | ||||
|  * | ||||
|  * $Id: protocolext.c,v 1.10 2007/10/19 22:56:25 rahrenbe Exp $ | ||||
|  * $Id: protocolext.c,v 1.11 2007/10/20 11:36:21 ajhseppa Exp $ | ||||
|  */ | ||||
|  | ||||
| #include <sys/wait.h> | ||||
| @@ -187,6 +187,11 @@ void cIptvProtocolExt::TerminateCommand(void) | ||||
| int cIptvProtocolExt::Read(unsigned char* *BufferAddr) | ||||
| { | ||||
|   //debug("cIptvProtocolExt::Read()\n"); | ||||
|   // Error out if socket not initialized | ||||
|   if (socketDesc <= 0) { | ||||
|     error("ERROR: Invalid socket in %s\n", __FUNCTION__); | ||||
|     return -1; | ||||
|   } | ||||
|   socklen_t addrlen = sizeof(sockAddr); | ||||
|   // Set argument point to read buffer | ||||
|   *BufferAddr = readBuffer; | ||||
| @@ -203,14 +208,21 @@ int cIptvProtocolExt::Read(unsigned char* *BufferAddr) | ||||
|   if (retval < 0) { | ||||
|      char tmp[64]; | ||||
|      error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp))); | ||||
|      return -1; | ||||
|      return retval; | ||||
|      } | ||||
|   // Check if data available | ||||
|   else if (retval) { | ||||
|      // Read data from socket | ||||
|      int len = recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT, | ||||
|                         (struct sockaddr *)&sockAddr, &addrlen); | ||||
|      if ((len > 0) && (readBuffer[0] == 0x47)) { | ||||
|      int len = 0; | ||||
|      if (isActive) | ||||
|         len = recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT, | ||||
|                        (struct sockaddr *)&sockAddr, &addrlen); | ||||
|      if (len < 0) { | ||||
|         char tmp[64]; | ||||
|         error("ERROR: recvfrom(): %s", strerror_r(errno, tmp, sizeof(tmp))); | ||||
|         return len; | ||||
|         } | ||||
|      else if ((len > 0) && (readBuffer[0] == 0x47)) { | ||||
|         // Set argument point to read buffer | ||||
|         *BufferAddr = &readBuffer[0]; | ||||
|         return len; | ||||
| @@ -256,6 +268,7 @@ bool cIptvProtocolExt::Open(void) | ||||
|   OpenSocket(); | ||||
|   // Execute the external command | ||||
|   ExecuteCommand(); | ||||
|   isActive = true; | ||||
|   return true; | ||||
| } | ||||
|  | ||||
| @@ -266,6 +279,7 @@ bool cIptvProtocolExt::Close(void) | ||||
|   CloseSocket(); | ||||
|   // Terminate the external script | ||||
|   TerminateCommand(); | ||||
|   isActive = false; | ||||
|   return true; | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
|  * | ||||
|  * See the README file for copyright information and how to reach the author. | ||||
|  * | ||||
|  * $Id: protocolhttp.c,v 1.12 2007/10/19 22:18:55 rahrenbe Exp $ | ||||
|  * $Id: protocolhttp.c,v 1.13 2007/10/20 11:36:21 ajhseppa Exp $ | ||||
|  */ | ||||
|  | ||||
| #include <sys/types.h> | ||||
| @@ -307,6 +307,11 @@ bool cIptvProtocolHttp::ProcessHeaders(void) | ||||
| int cIptvProtocolHttp::Read(unsigned char* *BufferAddr) | ||||
| { | ||||
|   //debug("cIptvProtocolHttp::Read()\n"); | ||||
|   // Error out if socket not initialized | ||||
|   if (socketDesc <= 0) { | ||||
|     error("ERROR: Invalid socket in %s\n", __FUNCTION__); | ||||
|     return -1; | ||||
|   } | ||||
|   socklen_t addrlen = sizeof(sockAddr); | ||||
|   // Set argument point to read buffer | ||||
|   *BufferAddr = readBuffer; | ||||
| @@ -323,13 +328,14 @@ int cIptvProtocolHttp::Read(unsigned char* *BufferAddr) | ||||
|   if (retval < 0) { | ||||
|      char tmp[64]; | ||||
|      error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp))); | ||||
|      return -1; | ||||
|      return retval; | ||||
|      } | ||||
|   // Check if data available | ||||
|   else if (retval) { | ||||
|      // Read data from socket | ||||
|      return recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT, | ||||
|                      (struct sockaddr *)&sockAddr, &addrlen); | ||||
|      if (isActive) | ||||
|         return recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT, | ||||
|                         (struct sockaddr *)&sockAddr, &addrlen); | ||||
|      } | ||||
|   return 0; | ||||
| } | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
|  * | ||||
|  * See the README file for copyright information and how to reach the author. | ||||
|  * | ||||
|  * $Id: protocoludp.c,v 1.13 2007/10/19 22:18:55 rahrenbe Exp $ | ||||
|  * $Id: protocoludp.c,v 1.14 2007/10/20 11:36:21 ajhseppa Exp $ | ||||
|  */ | ||||
|  | ||||
| #include <sys/types.h> | ||||
| @@ -155,6 +155,11 @@ bool cIptvProtocolUdp::DropMulticast(void) | ||||
| int cIptvProtocolUdp::Read(unsigned char* *BufferAddr) | ||||
| { | ||||
|   //debug("cIptvProtocolUdp::Read()\n"); | ||||
|   // Error out if socket not initialized | ||||
|   if (socketDesc <= 0) { | ||||
|     error("ERROR: Invalid socket in %s\n", __FUNCTION__); | ||||
|     return -1; | ||||
|   } | ||||
|   socklen_t addrlen = sizeof(sockAddr); | ||||
|   // Set argument point to read buffer | ||||
|   *BufferAddr = readBuffer; | ||||
| @@ -171,14 +176,21 @@ int cIptvProtocolUdp::Read(unsigned char* *BufferAddr) | ||||
|   if (retval < 0) { | ||||
|      char tmp[64]; | ||||
|      error("ERROR: select(): %s", strerror_r(errno, tmp, sizeof(tmp))); | ||||
|      return -1; | ||||
|      return retval; | ||||
|      } | ||||
|   // Check if data available | ||||
|   else if (retval) { | ||||
|      int len = 0; | ||||
|      // Read data from socket | ||||
|      int len = recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT, | ||||
|                         (struct sockaddr *)&sockAddr, &addrlen); | ||||
|      if ((len > 0) && (readBuffer[0] == 0x47)) { | ||||
|      if (isActive) | ||||
|         len = recvfrom(socketDesc, readBuffer, readBufferLen, MSG_DONTWAIT, | ||||
|                        (struct sockaddr *)&sockAddr, &addrlen); | ||||
|      if (len < 0) { | ||||
|         char tmp[64]; | ||||
|         error("ERROR: recvfrom(): %s", strerror_r(errno, tmp, sizeof(tmp))); | ||||
|         return len; | ||||
|         } | ||||
|      else if ((len > 0) && (readBuffer[0] == 0x47)) { | ||||
|         // Set argument point to read buffer | ||||
|         *BufferAddr = &readBuffer[0]; | ||||
|         return len; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user