Changeset 8298425 for message.c


Ignore:
Timestamp:
Dec 30, 2004, 3:38:59 PM (16 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
74037d9
Parents:
fe39450
Message:
Don't crash on super-long hostnames
Improved test for finding libdes425
File:
1 edited

Legend:

Unmodified
Added
Removed
  • message.c

    rba9f236 r8298425  
    1919  owl_message_set_direction_none(m);
    2020  m->delete=0;
    21   strcpy(m->hostname, "");
     21  m->hostname=owl_strdup("");
    2222  m->zwriteline=strdup("");
    2323  m->invalid_format=1;
     
    463463}
    464464#endif
     465
     466void owl_message_set_hostname(owl_message *m, char *hostname)
     467{
     468  if (m==NULL) return;
     469  if (m->hostname!=NULL) {
     470    owl_free(m->hostname);
     471  }
     472  m->hostname=owl_strdup(hostname);
     473}
    465474
    466475char *owl_message_get_hostname(owl_message *m)
     
    815824  hent=gethostbyaddr((char *) &(n->z_uid.zuid_addr), sizeof(n->z_uid.zuid_addr), AF_INET);
    816825  if (hent && hent->h_name) {
    817     strcpy(m->hostname, hent->h_name);
     826    owl_message_set_hostname(m, hent->h_name);
    818827  } else {
    819     strcpy(m->hostname, inet_ntoa(n->z_sender_addr));
     828    owl_message_set_hostname(m, inet_ntoa(n->z_sender_addr));
    820829  }
    821830}
     
    870879  /* save the hostname */
    871880  owl_function_debugmsg("create_pseudo_login: host is %s", host ? host : "");
    872   strcpy(m->hostname, host ? host : "");
     881  owl_message_set_hostname(m, host ? host : "");
    873882  owl_free(longuser);
    874883}
     
    878887  owl_zwrite z;
    879888  int ret;
     889  char hostbuff[5000];
    880890 
    881891  owl_message_init(m);
     
    901911 
    902912  /* save the hostname */
    903   ret=gethostname(m->hostname, MAXHOSTNAMELEN);
     913  ret=gethostname(hostbuff, MAXHOSTNAMELEN);
     914  hostbuff[MAXHOSTNAMELEN]='\0';
    904915  if (ret) {
    905     strcpy(m->hostname, "localhost");
    906   }
    907 
     916    owl_message_set_hostname(m, "localhost");
     917  } else {
     918    owl_message_set_hostname(m, hostbuff);
     919  }
    908920  owl_zwrite_free(&z);
    909921}
Note: See TracChangeset for help on using the changeset viewer.