diff options
author | Damien Miller <djm@mindrot.org> | 2006-03-26 14:19:21 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2006-03-26 14:19:21 +1100 |
commit | 07d86bec5eeaf19fe33dca99c8ebcbe9a77c3938 (patch) | |
tree | 098295eee2d7ec7b116b0db3ac4b580713dd5ab0 /sshd.c | |
parent | 7cd4579eb3c5afd22ae24436fd2611cd3aa0150a (diff) |
- djm@cvs.openbsd.org 2006/03/25 00:05:41
[auth-bsdauth.c auth-skey.c auth.c auth2-chall.c channels.c]
[clientloop.c deattack.c gss-genr.c kex.c key.c misc.c moduli.c]
[monitor.c monitor_wrap.c packet.c scard.c sftp-server.c ssh-agent.c]
[ssh-keyscan.c ssh.c sshconnect.c sshconnect2.c sshd.c uuencode.c]
[xmalloc.c xmalloc.h]
introduce xcalloc() and xasprintf() failure-checked allocations
functions and use them throughout openssh
xcalloc is particularly important because malloc(nmemb * size) is a
dangerous idiom (subject to integer overflow) and it is time for it
to die
feedback and ok deraadt@
Diffstat (limited to 'sshd.c')
-rw-r--r-- | sshd.c | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -891,7 +891,7 @@ main(int ac, char **av) | |||
891 | { | 891 | { |
892 | extern char *optarg; | 892 | extern char *optarg; |
893 | extern int optind; | 893 | extern int optind; |
894 | int opt, j, i, fdsetsz, on = 1; | 894 | int opt, j, i, on = 1; |
895 | int sock_in = -1, sock_out = -1, newsock = -1; | 895 | int sock_in = -1, sock_out = -1, newsock = -1; |
896 | pid_t pid; | 896 | pid_t pid; |
897 | socklen_t fromlen; | 897 | socklen_t fromlen; |
@@ -1110,7 +1110,7 @@ main(int ac, char **av) | |||
1110 | debug("sshd version %.100s", SSH_RELEASE); | 1110 | debug("sshd version %.100s", SSH_RELEASE); |
1111 | 1111 | ||
1112 | /* load private host keys */ | 1112 | /* load private host keys */ |
1113 | sensitive_data.host_keys = xmalloc(options.num_host_key_files * | 1113 | sensitive_data.host_keys = xcalloc(options.num_host_key_files, |
1114 | sizeof(Key *)); | 1114 | sizeof(Key *)); |
1115 | for (i = 0; i < options.num_host_key_files; i++) | 1115 | for (i = 0; i < options.num_host_key_files; i++) |
1116 | sensitive_data.host_keys[i] = NULL; | 1116 | sensitive_data.host_keys[i] = NULL; |
@@ -1212,7 +1212,7 @@ main(int ac, char **av) | |||
1212 | debug("setgroups() failed: %.200s", strerror(errno)); | 1212 | debug("setgroups() failed: %.200s", strerror(errno)); |
1213 | 1213 | ||
1214 | if (rexec_flag) { | 1214 | if (rexec_flag) { |
1215 | rexec_argv = xmalloc(sizeof(char *) * (rexec_argc + 2)); | 1215 | rexec_argv = xcalloc(rexec_argc + 2, sizeof(char *)); |
1216 | for (i = 0; i < rexec_argc; i++) { | 1216 | for (i = 0; i < rexec_argc; i++) { |
1217 | debug("rexec_argv[%d]='%s'", i, saved_argv[i]); | 1217 | debug("rexec_argv[%d]='%s'", i, saved_argv[i]); |
1218 | rexec_argv[i] = saved_argv[i]; | 1218 | rexec_argv[i] = saved_argv[i]; |
@@ -1391,7 +1391,7 @@ main(int ac, char **av) | |||
1391 | if (listen_socks[i] > maxfd) | 1391 | if (listen_socks[i] > maxfd) |
1392 | maxfd = listen_socks[i]; | 1392 | maxfd = listen_socks[i]; |
1393 | /* pipes connected to unauthenticated childs */ | 1393 | /* pipes connected to unauthenticated childs */ |
1394 | startup_pipes = xmalloc(options.max_startups * sizeof(int)); | 1394 | startup_pipes = xcalloc(options.max_startups, sizeof(int)); |
1395 | for (i = 0; i < options.max_startups; i++) | 1395 | for (i = 0; i < options.max_startups; i++) |
1396 | startup_pipes[i] = -1; | 1396 | startup_pipes[i] = -1; |
1397 | 1397 | ||
@@ -1404,9 +1404,8 @@ main(int ac, char **av) | |||
1404 | sighup_restart(); | 1404 | sighup_restart(); |
1405 | if (fdset != NULL) | 1405 | if (fdset != NULL) |
1406 | xfree(fdset); | 1406 | xfree(fdset); |
1407 | fdsetsz = howmany(maxfd+1, NFDBITS) * sizeof(fd_mask); | 1407 | fdset = (fd_set *)xcalloc(howmany(maxfd + 1, NFDBITS), |
1408 | fdset = (fd_set *)xmalloc(fdsetsz); | 1408 | sizeof(fd_mask)); |
1409 | memset(fdset, 0, fdsetsz); | ||
1410 | 1409 | ||
1411 | for (i = 0; i < num_listen_socks; i++) | 1410 | for (i = 0; i < num_listen_socks; i++) |
1412 | FD_SET(listen_socks[i], fdset); | 1411 | FD_SET(listen_socks[i], fdset); |
@@ -1713,8 +1712,7 @@ main(int ac, char **av) | |||
1713 | packet_set_nonblocking(); | 1712 | packet_set_nonblocking(); |
1714 | 1713 | ||
1715 | /* allocate authentication context */ | 1714 | /* allocate authentication context */ |
1716 | authctxt = xmalloc(sizeof(*authctxt)); | 1715 | authctxt = xcalloc(1, sizeof(*authctxt)); |
1717 | memset(authctxt, 0, sizeof(*authctxt)); | ||
1718 | 1716 | ||
1719 | authctxt->loginmsg = &loginmsg; | 1717 | authctxt->loginmsg = &loginmsg; |
1720 | 1718 | ||