@@ -231,6 +231,7 @@ static int nacl;
231231#define MAX_CONNECT_PORTS 64
232232static int connect_ports [MAX_CONNECT_PORTS ] = { 443 };
233233static int nconnect_ports = 1 ;
234+ static int connect_port_wildcard ;
234235
235236/* forward declarations */
236237static void conn_close (struct conn * );
@@ -533,22 +534,24 @@ acl_check(struct sockaddr *sa)
533534}
534535
535536/*
536- * Check if a CONNECT port is allowed.
537- * Returns 1 if allowed, 0 if denied .
537+ * Check whether a CONNECT port is allowed.
538+ * Returns 0 if denied, 1 if explicitly listed, 2 if wildcard .
538539 */
539540static int
540541connect_port_allowed (const char * port )
541542{
542543 int p , i ;
543544
544- if (nconnect_ports == 0 )
545+ if (nconnect_ports == 0 && ! connect_port_wildcard )
545546 return 1 ;
546547
547548 p = (int )strtoll (port , NULL , 10 );
548549 for (i = 0 ; i < nconnect_ports ; i ++ ) {
549550 if (connect_ports [i ] == p )
550551 return 1 ;
551552 }
553+ if (connect_port_wildcard )
554+ return 2 ;
552555 return 0 ;
553556}
554557
@@ -710,6 +713,7 @@ config_reset(void)
710713 nacl = 0 ;
711714 connect_ports [0 ] = 443 ;
712715 nconnect_ports = 1 ;
716+ connect_port_wildcard = 0 ;
713717}
714718
715719static int
@@ -863,7 +867,7 @@ parse_config(const char *path, int must_exist)
863867 cfg_deny_private = b ;
864868 } else if (strcasecmp (key , "connect_port" ) == 0 ) {
865869 const char * errstr ;
866- int n = (int )strtonum (val , 1 , 65535 , & errstr );
870+ int n = (int )strtonum (val , 0 , 65535 , & errstr );
867871 if (errstr != NULL ) {
868872 logmsg (LOG_ERR ,
869873 "%s:%d: connect_port: %s" ,
@@ -873,16 +877,21 @@ parse_config(const char *path, int must_exist)
873877 }
874878 if (!connect_port_seen ) {
875879 nconnect_ports = 0 ;
880+ connect_port_wildcard = 0 ;
876881 connect_port_seen = 1 ;
877882 }
878- if (nconnect_ports >= MAX_CONNECT_PORTS ) {
879- logmsg (LOG_ERR ,
880- "%s:%d: too many connect_port entries" ,
881- path , lineno );
882- fclose (fp );
883- return -1 ;
883+ if (n == 0 ) {
884+ connect_port_wildcard = 1 ;
885+ } else {
886+ if (nconnect_ports >= MAX_CONNECT_PORTS ) {
887+ logmsg (LOG_ERR ,
888+ "%s:%d: too many connect_port "
889+ "entries" , path , lineno );
890+ fclose (fp );
891+ return -1 ;
892+ }
893+ connect_ports [nconnect_ports ++ ] = n ;
884894 }
885- connect_ports [nconnect_ports ++ ] = n ;
886895 } else {
887896 logmsg (LOG_ERR , "%s:%d: unknown directive: %s" ,
888897 path , lineno , key );
@@ -1323,11 +1332,17 @@ handle_request(struct conn *c)
13231332 logmsg (LOG_INFO , "%s" , logbuf );
13241333 }
13251334
1326- if (is_connect && !connect_port_allowed (port )) {
1327- logmsg (LOG_WARNING , "CONNECT port %s denied" , port );
1328- ign_write (c -> cfd , ERR_403 , sizeof (ERR_403 ) - 1 );
1329- conn_close (c );
1330- return ;
1335+ if (is_connect ) {
1336+ int prc = connect_port_allowed (port );
1337+ if (prc == 0 ) {
1338+ logmsg (LOG_WARNING , "CONNECT port %s denied" , port );
1339+ ign_write (c -> cfd , ERR_403 , sizeof (ERR_403 ) - 1 );
1340+ conn_close (c );
1341+ return ;
1342+ }
1343+ if (prc == 2 )
1344+ logmsg (LOG_WARNING ,
1345+ "CONNECT port %s allowed (wildcard)" , port );
13311346 }
13321347
13331348 if (!is_connect ) {
0 commit comments