From 1404859ff2fa4ddc9bca65bddb2935d2e3dc24b4 Mon Sep 17 00:00:00 2001 From: russell Date: Sun, 15 May 2005 15:55:31 +0000 Subject: ensure that calls to gethostbyname are null terminated, also use MAXHOSTNAMELEN where appropriate (bug #4198) (bug #4212) git-svn-id: http://svn.digium.com/svn/asterisk/branches/v1-0@5675 f38db490-d61c-443f-a65b-d21fe96a405b --- asterisk.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'asterisk.c') diff --git a/asterisk.c b/asterisk.c index 1bf800d4c..146f43a71 100755 --- a/asterisk.c +++ b/asterisk.c @@ -264,12 +264,12 @@ static pthread_t lthread; static void *netconsole(void *vconsole) { struct console *con = vconsole; - char hostname[256]; + char hostname[MAXHOSTNAMELEN]=""; char tmp[512]; int res; struct pollfd fds[2]; - if (gethostname(hostname, sizeof(hostname))) + if (gethostname(hostname, sizeof(hostname)-1)) strncpy(hostname, "", sizeof(hostname)-1); snprintf(tmp, sizeof(tmp), "%s/%d/%s\n", hostname, ast_mainpid, ASTERISK_VERSION); fdprint(con->fd, tmp); @@ -964,7 +964,7 @@ static char *cli_prompt(EditLine *el) memset(prompt, 0, sizeof(prompt)); while (*t != '\0' && *p < sizeof(prompt)) { if (*t == '%') { - char hostname[256]; + char hostname[MAXHOSTNAMELEN]=""; int i; struct timeval tv; struct tm tm; @@ -1572,7 +1572,7 @@ int main(int argc, char *argv[]) { int c; char filename[80] = ""; - char hostname[256]; + char hostname[MAXHOSTNAMELEN]=""; char tmp[80]; char * xarg = NULL; int x; @@ -1597,7 +1597,7 @@ int main(int argc, char *argv[]) option_remote++; option_nofork++; } - if (gethostname(hostname, sizeof(hostname))) + if (gethostname(hostname, sizeof(hostname)-1)) strncpy(hostname, "", sizeof(hostname)-1); ast_mainpid = getpid(); ast_ulaw_init(); -- cgit v1.2.3