diff options
author | 2006-03-25 00:05:40 +0000 | |
---|---|---|
committer | 2006-03-25 00:05:40 +0000 | |
commit | f846f1e36b1b1e10541c6b59635584eae5734f55 (patch) | |
tree | 2586060455068676ade98385f9252325c62f52a3 /usr.bin/ssh/channels.c | |
parent | oops, chip misnamed; roman.hunt@comcast.net (diff) | |
download | wireguard-openbsd-f846f1e36b1b1e10541c6b59635584eae5734f55.tar.xz wireguard-openbsd-f846f1e36b1b1e10541c6b59635584eae5734f55.zip |
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 'usr.bin/ssh/channels.c')
-rw-r--r-- | usr.bin/ssh/channels.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/usr.bin/ssh/channels.c b/usr.bin/ssh/channels.c index a27269c2645..ce863f00e53 100644 --- a/usr.bin/ssh/channels.c +++ b/usr.bin/ssh/channels.c @@ -248,7 +248,7 @@ channel_new(char *ctype, int type, int rfd, int wfd, int efd, /* Do initial allocation if this is the first call. */ if (channels_alloc == 0) { channels_alloc = 10; - channels = xmalloc(channels_alloc * sizeof(Channel *)); + channels = xcalloc(channels_alloc, sizeof(Channel *)); for (i = 0; i < channels_alloc; i++) channels[i] = NULL; } @@ -273,8 +273,7 @@ channel_new(char *ctype, int type, int rfd, int wfd, int efd, channels[i] = NULL; } /* Initialize and return new channel. */ - c = channels[found] = xmalloc(sizeof(Channel)); - memset(c, 0, sizeof(Channel)); + c = channels[found] = xcalloc(1, sizeof(Channel)); buffer_init(&c->input); buffer_init(&c->output); buffer_init(&c->extended); @@ -2808,7 +2807,7 @@ x11_create_display_inet(int x11_display_offset, int x11_use_localhost, } /* Allocate a channel for each socket. */ - *chanids = xmalloc(sizeof(**chanids) * (num_socks + 1)); + *chanids = xcalloc(num_socks + 1, sizeof(**chanids)); for (n = 0; n < num_socks; n++) { sock = socks[n]; nc = channel_new("x11 listener", |