httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@arctic.org>
Subject [PATCH] more signed/unsigned port cleanups
Date Mon, 07 Apr 1997 05:50:46 GMT
I created this patch because of a report by an alpha user that they were
getting "cannot bind to port 202" for some obscure reason... I can't
explain that, but the patch is needed. 

It cleans up more signed/unsigned short issues with port numbers.  Note
that I didn't use strtoul() where I really should have to replace atoi() 
because I'm not sure of the portability of strtoul().  It touches
mod_rewrite.

Yes Alexei is right we need to bump the module revision number.  But we're
going to do that for 1.2 release anyhow I'm assuming... actually I'd +1 a
bump with every release tarball.

Dean

P.S. Alexei I think that the high bit is always required to be the sign
bit because of the defined semantics of the >> operator when working on
signed integers -- it's defined to extend the sign bit. 

Index: http_config.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_config.c,v
retrieving revision 1.47
diff -c -3 -r1.47 http_config.c
*** http_config.c	1997/03/22 23:51:01	1.47
--- http_config.c	1997/04/07 05:44:29
***************
*** 849,855 ****
   * *paddr is the variable used to keep track of **paddr between calls
   * port is the default port to assume
   */
! static void get_addresses (pool *p, char *w, server_addr_rec ***paddr, int port)
  {
      struct hostent *hep;
      unsigned long my_addr;
--- 849,855 ----
   * *paddr is the variable used to keep track of **paddr between calls
   * port is the default port to assume
   */
! static void get_addresses (pool *p, char *w, server_addr_rec ***paddr, unsigned port)
  {
      struct hostent *hep;
      unsigned long my_addr;
Index: http_core.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_core.c,v
retrieving revision 1.76
diff -c -3 -r1.76 http_core.c
*** http_core.c	1997/04/06 07:43:40	1.76
--- http_core.c	1997/04/07 05:44:30
***************
*** 1108,1114 ****
  {
      listen_rec *new;
      char *ports;
!     int port;
  
      if (cmd->server->is_virtual) return "Listen not allowed in <VirtualHost>";
      ports=strchr(ips, ':');
--- 1108,1114 ----
  {
      listen_rec *new;
      char *ports;
!     unsigned port;
  
      if (cmd->server->is_virtual) return "Listen not allowed in <VirtualHost>";
      ports=strchr(ips, ':');
Index: http_main.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_main.c,v
retrieving revision 1.134
diff -c -3 -r1.134 http_main.c
*** http_main.c	1997/04/06 07:43:39	1.134
--- http_main.c	1997/04/07 05:44:30
***************
*** 1401,1408 ****
  pool *pconf;			/* Pool for config stuff */
  pool *ptrans;			/* Pool for per-transaction stuff */
  
! server_rec *find_virtual_server (struct in_addr server_ip, int port,
! 				 server_rec *server)
  {
      server_rec *virt;
      server_addr_rec *sar;
--- 1401,1408 ----
  pool *pconf;			/* Pool for config stuff */
  pool *ptrans;			/* Pool for per-transaction stuff */
  
! static server_rec *find_virtual_server (struct in_addr server_ip,
! 				unsigned port, server_rec *server)
  {
      server_rec *virt;
      server_addr_rec *sar;
***************
*** 1438,1444 ****
      int n;
      server_addr_rec *sar;
      int has_default_vhost_addr;
!     int mainport = s->port;
      int from_local=0;  
  
      /* Main host first */
--- 1438,1444 ----
      int n;
      server_addr_rec *sar;
      int has_default_vhost_addr;
!     unsigned mainport = s->port;
      int from_local=0;  
  
      /* Main host first */
Index: http_protocol.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_protocol.c,v
retrieving revision 1.111
diff -c -3 -r1.111 http_protocol.c
*** http_protocol.c	1997/04/06 07:43:39	1.111
--- http_protocol.c	1997/04/07 05:44:31
***************
*** 547,553 ****
  
  const char *check_fulluri (request_rec *r, const char *uri) {
    char *name, *host;
!   int i, port;
  
    /* This routine parses full URLs, if they match the server */
    if (strncmp(uri, "http://", 7)) return uri;
--- 547,554 ----
  
  const char *check_fulluri (request_rec *r, const char *uri) {
    char *name, *host;
!   int i;
!   unsigned port;
  
    /* This routine parses full URLs, if they match the server */
    if (strncmp(uri, "http://", 7)) return uri;
***************
*** 674,680 ****
  static void check_hostalias (request_rec *r) {
    const char *hostname=r->hostname;
    char *host = getword(r->pool, &hostname, ':');	/* Get rid of port */
!   int port = (*hostname) ? atoi(hostname) : 80;
    server_rec *s;
    int l;
  
--- 675,681 ----
  static void check_hostalias (request_rec *r) {
    const char *hostname=r->hostname;
    char *host = getword(r->pool, &hostname, ':');	/* Get rid of port */
!   unsigned port = (*hostname) ? atoi(hostname) : 80;
    server_rec *s;
    int l;
  
Index: httpd.h
===================================================================
RCS file: /export/home/cvs/apache/src/httpd.h,v
retrieving revision 1.93
diff -c -3 -r1.93 httpd.h
*** httpd.h	1997/03/29 03:40:34	1.93
--- httpd.h	1997/04/07 05:44:31
***************
*** 665,671 ****
  char *os_escape_path(pool *p,const char *path,int partial);
  #define escape_uri(ppool,path) os_escape_path(ppool,path,1)
  extern char *escape_html(pool *p, const char *s);
! char *construct_server(pool *p, const char *hostname, int port);
  char *construct_url (pool *p, const char *path, const server_rec *s);     
  char *escape_shell_cmd (pool *p, const char *s);
       
--- 665,671 ----
  char *os_escape_path(pool *p,const char *path,int partial);
  #define escape_uri(ppool,path) os_escape_path(ppool,path,1)
  extern char *escape_html(pool *p, const char *s);
! char *construct_server(pool *p, const char *hostname, unsigned port);
  char *construct_url (pool *p, const char *path, const server_rec *s);     
  char *escape_shell_cmd (pool *p, const char *s);
       
***************
*** 700,705 ****
  void chdir_file(const char *file);
       
  char *get_local_host(pool *);
! unsigned long get_virthost_addr (const char *hostname, short int *port);
  
  extern time_t restart_time;
--- 700,705 ----
  void chdir_file(const char *file);
       
  char *get_local_host(pool *);
! unsigned long get_virthost_addr (const char *hostname, unsigned short *port);
  
  extern time_t restart_time;
Index: mod_imap.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_imap.c,v
retrieving revision 1.20
diff -c -3 -r1.20 mod_imap.c
*** mod_imap.c	1997/04/06 07:43:41	1.20
--- mod_imap.c	1997/04/07 05:44:31
***************
*** 367,373 ****
    char my_base[SMALLBUF] = {'\0'};
  
    if ( ! strcasecmp(value, "map" ) || ! strcasecmp(value, "menu") ) {
!     if (r->server->port == 80 ) { 
        ap_snprintf(url, SMALLBUF,
  		"http://%s%s", r->server->server_hostname, r->uri);
      }
--- 367,373 ----
    char my_base[SMALLBUF] = {'\0'};
  
    if ( ! strcasecmp(value, "map" ) || ! strcasecmp(value, "menu") ) {
!     if (r->server->port == DEFAULT_PORT ) { 
        ap_snprintf(url, SMALLBUF,
  		"http://%s%s", r->server->server_hostname, r->uri);
      }
***************
*** 411,420 ****
        url[SMALLBUF-1] = '\0';
      }         
      else {                  
!       if (r->server->port == 80 ) {  
  	ap_snprintf(url, SMALLBUF, "http://%s/", r->server->server_hostname);
        }            
!       if (r->server->port != 80 ) {
  	ap_snprintf(url, SMALLBUF, "http://%s:%d/",
  		r->server->server_hostname, r->server->port);
        }                     /* no base, no value: pick a simple default */
--- 411,420 ----
        url[SMALLBUF-1] = '\0';
      }         
      else {                  
!       if (r->server->port == DEFAULT_PORT ) {  
  	ap_snprintf(url, SMALLBUF, "http://%s/", r->server->server_hostname);
        }            
!       if (r->server->port != DEFAULT_PORT ) {
  	ap_snprintf(url, SMALLBUF, "http://%s:%d/",
  		r->server->server_hostname, r->server->port);
        }                     /* no base, no value: pick a simple default */
Index: mod_info.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_info.c,v
retrieving revision 1.15
diff -c -3 -r1.15 mod_info.c
*** mod_info.c	1997/04/06 07:43:42	1.15
--- mod_info.c	1997/04/07 05:44:31
***************
*** 312,318 ****
  			rputs(buf,r);
  			ap_snprintf(buf, sizeof(buf), "<strong>User/Group:</strong> <tt>%s(%d)/%d</tt><br>\n",user_name,(int)user_id,(int)group_id);
  			rputs(buf,r);
! 			ap_snprintf(buf, sizeof(buf), "<strong>Hostname/port:</strong> <tt>%s:%d</tt><br>\n",serv->server_hostname,serv->port);
  			rputs(buf,r);
  			ap_snprintf(buf, sizeof(buf), "<strong>Daemons:</strong> <tt>start:
%d &nbsp;&nbsp; min idle: %d &nbsp;&nbsp; max idle: %d &nbsp;&nbsp;
max: %d</tt><br>\n",daemons_to_start,daemons_min_free,daemons_max_free,daemons_limit);
  			rputs(buf,r);
--- 312,318 ----
  			rputs(buf,r);
  			ap_snprintf(buf, sizeof(buf), "<strong>User/Group:</strong> <tt>%s(%d)/%d</tt><br>\n",user_name,(int)user_id,(int)group_id);
  			rputs(buf,r);
! 			ap_snprintf(buf, sizeof(buf), "<strong>Hostname/port:</strong> <tt>%s:%u</tt><br>\n",serv->server_hostname,serv->port);
  			rputs(buf,r);
  			ap_snprintf(buf, sizeof(buf), "<strong>Daemons:</strong> <tt>start:
%d &nbsp;&nbsp; min idle: %d &nbsp;&nbsp; max idle: %d &nbsp;&nbsp;
max: %d</tt><br>\n",daemons_to_start,daemons_min_free,daemons_max_free,daemons_limit);
  			rputs(buf,r);
Index: mod_log_config.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_log_config.c,v
retrieving revision 1.26
diff -c -3 -r1.26 mod_log_config.c
*** mod_log_config.c	1997/03/22 23:51:02	1.26
--- mod_log_config.c	1997/04/07 05:44:31
***************
*** 330,336 ****
  char *log_server_port (request_rec *r, char *a) {
      char portnum[22];
  
!     ap_snprintf(portnum, sizeof(portnum), "%d", r->server->port);
      return pstrdup(r->pool, portnum);
  }
  
--- 330,336 ----
  char *log_server_port (request_rec *r, char *a) {
      char portnum[22];
  
!     ap_snprintf(portnum, sizeof(portnum), "%u", r->server->port);
      return pstrdup(r->pool, portnum);
  }
  
Index: mod_rewrite.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_rewrite.c,v
retrieving revision 1.24
diff -c -3 -r1.24 mod_rewrite.c
*** mod_rewrite.c	1997/03/29 01:55:57	1.24
--- mod_rewrite.c	1997/04/07 05:44:32
***************
*** 878,891 ****
      /* add the canonical URI of this URL */
      thisserver = r->server->server_hostname;
  #ifdef APACHE_SSL
!     if (((!r->connection->client->ssl) && (r->server->port == 80))
||
           ((r->connection->client->ssl) && (r->server->port == 443)))
  #else
!     if (r->server->port == 80)
  #endif 
          thisport = "";
      else {
!         ap_snprintf(buf, sizeof(buf), ":%d", r->server->port);
          thisport = pstrdup(r->pool, buf);
      }
      thisurl = table_get(r->subprocess_env, ENVVAR_SCRIPT_URL);
--- 878,891 ----
      /* add the canonical URI of this URL */
      thisserver = r->server->server_hostname;
  #ifdef APACHE_SSL
!     if (((!r->connection->client->ssl) && (r->server->port == DEFAULT_PORT))
||
           ((r->connection->client->ssl) && (r->server->port == 443)))
  #else
!     if (r->server->port == DEFAULT_PORT)
  #endif 
          thisport = "";
      else {
!         ap_snprintf(buf, sizeof(buf), ":%u", r->server->port);
          thisport = pstrdup(r->pool, buf);
      }
      thisurl = table_get(r->subprocess_env, ENVVAR_SCRIPT_URL);
***************
*** 1618,1631 ****
                      strncmp(r->filename, "ftp://", 6) == 0)    ) {
  
  #ifdef APACHE_SSL
!                 if ((!r->connection->client->ssl && r->server->port
== 80) ||
                      ( r->connection->client->ssl && r->server->port
== 443)  )
  #else
!                 if (r->server->port == 80)
  #endif
                      port[0] = '\0';
                  else 
!                     ap_snprintf(port, sizeof(port), ":%d", r->server->port);
                  if (r->filename[0] == '/')
  #ifdef APACHE_SSL
                      ap_snprintf(newuri, sizeof(newuri), "%s://%s%s%s", http_method(r), r->server->server_hostname,
port, r->filename);
--- 1618,1631 ----
                      strncmp(r->filename, "ftp://", 6) == 0)    ) {
  
  #ifdef APACHE_SSL
!                 if ((!r->connection->client->ssl && r->server->port
== DEFAULT_PORT) ||
                      ( r->connection->client->ssl && r->server->port
== 443)  )
  #else
!                 if (r->server->port == DEFAULT_PORT)
  #endif
                      port[0] = '\0';
                  else 
!                     ap_snprintf(port, sizeof(port), ":%u", r->server->port);
                  if (r->filename[0] == '/')
  #ifdef APACHE_SSL
                      ap_snprintf(newuri, sizeof(newuri), "%s://%s%s%s", http_method(r), r->server->server_hostname,
port, r->filename);
***************
*** 1806,1812 ****
  static void reduce_uri(request_rec *r)
  {
      char *cp;
!     short port;
      char *portp;
      char *hostp;
      char *url;
--- 1806,1812 ----
  static void reduce_uri(request_rec *r)
  {
      char *cp;
!     unsigned port;
      char *portp;
      char *hostp;
      char *url;
***************
*** 1860,1866 ****
              EOS_PARANOIA(host);
              *cp = '/';
              /* set port */
!             port = 80;
              /* set remaining url */
              url = cp;
          }
--- 1860,1866 ----
              EOS_PARANOIA(host);
              *cp = '/';
              /* set port */
!             port = DEFAULT_PORT;
              /* set remaining url */
              url = cp;
          }
***************
*** 1869,1875 ****
              strncpy(host, hostp, sizeof(host)-1);
              EOS_PARANOIA(host);
              /* set port */
!             port = 80;
              /* set remaining url */
              url = "/";
          }
--- 1869,1875 ----
              strncpy(host, hostp, sizeof(host)-1);
              EOS_PARANOIA(host);
              /* set port */
!             port = DEFAULT_PORT;
              /* set remaining url */
              url = "/";
          }
***************
*** 2579,2585 ****
          result = r->server->server_hostname;
      }
      else if (strcasecmp(var, "SERVER_PORT") == 0) {
!         ap_snprintf(resultbuf, sizeof(resultbuf), "%d", r->server->port);
          result = resultbuf;
      }
      else if (strcasecmp(var, "SERVER_PROTOCOL") == 0) {
--- 2579,2585 ----
          result = r->server->server_hostname;
      }
      else if (strcasecmp(var, "SERVER_PORT") == 0) {
!         ap_snprintf(resultbuf, sizeof(resultbuf), "%u", r->server->port);
          result = resultbuf;
      }
      else if (strcasecmp(var, "SERVER_PROTOCOL") == 0) {
Index: util.c
===================================================================
RCS file: /export/home/cvs/apache/src/util.c,v
retrieving revision 1.51
diff -c -3 -r1.51 util.c
*** util.c	1997/03/22 23:51:04	1.51
--- util.c	1997/04/07 05:44:32
***************
*** 782,795 ****
      else return OK;
  }
  
! char *construct_server(pool *p, const char *hostname, int port) {
      char portnum[22];		
  	/* Long enough, even if port > 16 bits for some reason */
    
!     if (port == 80)
  	return (char *)hostname;
      else {
!         ap_snprintf (portnum, sizeof(portnum), "%d", port);
  	return pstrcat (p, hostname, ":", portnum, NULL);
      }
  }
--- 782,795 ----
      else return OK;
  }
  
! char *construct_server(pool *p, const char *hostname, unsigned port) {
      char portnum[22];		
  	/* Long enough, even if port > 16 bits for some reason */
    
!     if (port == DEFAULT_PORT)
  	return (char *)hostname;
      else {
!         ap_snprintf (portnum, sizeof(portnum), "%u", port);
  	return pstrcat (p, hostname, ":", portnum, NULL);
      }
  }
***************
*** 1142,1148 ****
   * Parses a host of the form <address>[:port]
   * :port is permitted if 'port' is not NULL
   */
! unsigned long get_virthost_addr (const char *w, short int *ports) {
      struct hostent *hep;
      unsigned long my_addr;
      char *p;
--- 1142,1148 ----
   * Parses a host of the form <address>[:port]
   * :port is permitted if 'port' is not NULL
   */
! unsigned long get_virthost_addr (const char *w, unsigned short *ports) {
      struct hostent *hep;
      unsigned long my_addr;
      char *p;
Index: util_script.c
===================================================================
RCS file: /export/home/cvs/apache/src/util_script.c,v
retrieving revision 1.47
diff -c -3 -r1.47 util_script.c
*** util_script.c	1997/03/18 09:46:27	1.47
--- util_script.c	1997/04/07 05:44:32
***************
*** 176,182 ****
  	    table_set (e, http2env (r->pool, hdrs[i].key), hdrs[i].val);
      }
      
!     ap_snprintf(port, sizeof(port), "%d", s->port);
  
      if(!(env_path = getenv("PATH")))
          env_path=DEFAULT_PATH;
--- 176,182 ----
  	    table_set (e, http2env (r->pool, hdrs[i].key), hdrs[i].val);
      }
      
!     ap_snprintf(port, sizeof(port), "%u", s->port);
  
      if(!(env_path = getenv("PATH")))
          env_path=DEFAULT_PATH;



Mime
View raw message