Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -124,22 +124,38 @@ newWithClass: isa node: node service: service]; } - if ((se = getservbyname([service cString], "TCP")) != NULL) + if ((se = getservbyname([service cString], "tcp")) != NULL) port = se->s_port; - else if ((port = of_bswap16_if_le(strtol([service cString], NULL, - 10))) == 0) { + else { + @try { + intmax_t p = [service decimalValue]; + + if (p < 1 || p > 65535) + @throw [OFOutOfRangeException + newWithClass: isa]; + + port = of_bswap16_if_le(p); + } @catch (OFInvalidFormatException *e) { + [e release]; +# ifdef OF_THREADS + [addrlist release]; + [mutex unlock]; +# endif + @throw [OFAddressTranslationFailedException + newWithClass: isa + node: node + service: service]; + } @catch (id e) { # ifdef OF_THREADS - [addrlist release]; - [mutex unlock]; + [addrlist release]; + [mutex unlock]; # endif - @throw [OFAddressTranslationFailedException - newWithClass: isa - node: node - service: service]; + @throw e; + } } memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = port; @@ -251,21 +267,36 @@ newWithClass: isa node: node service: service]; } - if ((se = getservbyname([service cString], "TCP")) != NULL) + if ((se = getservbyname([service cString], "tcp")) != NULL) port = se->s_port; - else if ((port = of_bswap16_if_le(strtol([service cString], NULL, - 10))) == 0) { + else { + @try { + intmax_t p = [service decimalValue]; + + if (p < 1 || p > 65535) + @throw [OFOutOfRangeException + newWithClass: isa]; + + port = of_bswap16_if_le(p); + } @catch (OFInvalidFormatException *e) { + [e release]; +# ifdef OF_THREADS + [mutex unlock]; +# endif + @throw [OFAddressTranslationFailedException + newWithClass: isa + node: node + service: service]; + } @catch (id e) { # ifdef OF_THREADS - [mutex unlock]; + [mutex unlock]; # endif - @throw [OFAddressTranslationFailedException - newWithClass: isa - node: node - service: service]; + @throw e; + } } memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = port;