summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--channels.c14
-rw-r--r--misc.c4
-rw-r--r--mux.c4
-rw-r--r--readconf.c6
-rw-r--r--scp.c4
-rw-r--r--servconf.c4
-rw-r--r--session.c8
-rw-r--r--sftp-client.c4
-rw-r--r--sftp-server.c6
-rw-r--r--ssh-agent.c4
-rw-r--r--ssh-keygen.c4
-rw-r--r--ssh-pkcs11.c4
-rw-r--r--xmalloc.c18
-rw-r--r--xmalloc.h4
14 files changed, 40 insertions, 48 deletions
diff --git a/channels.c b/channels.c
index 9486c1cff..f72b8cc62 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.c,v 1.341 2015/02/06 23:21:59 millert Exp $ */ 1/* $OpenBSD: channels.c,v 1.342 2015/04/24 01:36:00 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -306,7 +306,7 @@ channel_new(char *ctype, int type, int rfd, int wfd, int efd,
306 if (channels_alloc > 10000) 306 if (channels_alloc > 10000)
307 fatal("channel_new: internal error: channels_alloc %d " 307 fatal("channel_new: internal error: channels_alloc %d "
308 "too big.", channels_alloc); 308 "too big.", channels_alloc);
309 channels = xrealloc(channels, channels_alloc + 10, 309 channels = xreallocarray(channels, channels_alloc + 10,
310 sizeof(Channel *)); 310 sizeof(Channel *));
311 channels_alloc += 10; 311 channels_alloc += 10;
312 debug2("channel: expanding %d", channels_alloc); 312 debug2("channel: expanding %d", channels_alloc);
@@ -2192,8 +2192,8 @@ channel_prepare_select(fd_set **readsetp, fd_set **writesetp, int *maxfdp,
2192 2192
2193 /* perhaps check sz < nalloc/2 and shrink? */ 2193 /* perhaps check sz < nalloc/2 and shrink? */
2194 if (*readsetp == NULL || sz > *nallocp) { 2194 if (*readsetp == NULL || sz > *nallocp) {
2195 *readsetp = xrealloc(*readsetp, nfdset, sizeof(fd_mask)); 2195 *readsetp = xreallocarray(*readsetp, nfdset, sizeof(fd_mask));
2196 *writesetp = xrealloc(*writesetp, nfdset, sizeof(fd_mask)); 2196 *writesetp = xreallocarray(*writesetp, nfdset, sizeof(fd_mask));
2197 *nallocp = sz; 2197 *nallocp = sz;
2198 } 2198 }
2199 *maxfdp = n; 2199 *maxfdp = n;
@@ -3237,7 +3237,7 @@ channel_request_remote_forwarding(struct Forward *fwd)
3237 } 3237 }
3238 if (success) { 3238 if (success) {
3239 /* Record that connection to this host/port is permitted. */ 3239 /* Record that connection to this host/port is permitted. */
3240 permitted_opens = xrealloc(permitted_opens, 3240 permitted_opens = xreallocarray(permitted_opens,
3241 num_permitted_opens + 1, sizeof(*permitted_opens)); 3241 num_permitted_opens + 1, sizeof(*permitted_opens));
3242 idx = num_permitted_opens++; 3242 idx = num_permitted_opens++;
3243 if (fwd->connect_path != NULL) { 3243 if (fwd->connect_path != NULL) {
@@ -3468,7 +3468,7 @@ channel_add_permitted_opens(char *host, int port)
3468{ 3468{
3469 debug("allow port forwarding to host %s port %d", host, port); 3469 debug("allow port forwarding to host %s port %d", host, port);
3470 3470
3471 permitted_opens = xrealloc(permitted_opens, 3471 permitted_opens = xreallocarray(permitted_opens,
3472 num_permitted_opens + 1, sizeof(*permitted_opens)); 3472 num_permitted_opens + 1, sizeof(*permitted_opens));
3473 permitted_opens[num_permitted_opens].host_to_connect = xstrdup(host); 3473 permitted_opens[num_permitted_opens].host_to_connect = xstrdup(host);
3474 permitted_opens[num_permitted_opens].port_to_connect = port; 3474 permitted_opens[num_permitted_opens].port_to_connect = port;
@@ -3518,7 +3518,7 @@ channel_add_adm_permitted_opens(char *host, int port)
3518{ 3518{
3519 debug("config allows port forwarding to host %s port %d", host, port); 3519 debug("config allows port forwarding to host %s port %d", host, port);
3520 3520
3521 permitted_adm_opens = xrealloc(permitted_adm_opens, 3521 permitted_adm_opens = xreallocarray(permitted_adm_opens,
3522 num_adm_permitted_opens + 1, sizeof(*permitted_adm_opens)); 3522 num_adm_permitted_opens + 1, sizeof(*permitted_adm_opens));
3523 permitted_adm_opens[num_adm_permitted_opens].host_to_connect 3523 permitted_adm_opens[num_adm_permitted_opens].host_to_connect
3524 = xstrdup(host); 3524 = xstrdup(host);
diff --git a/misc.c b/misc.c
index 38af3dfe3..ddd2b2db4 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: misc.c,v 1.96 2015/01/16 06:40:12 deraadt Exp $ */ 1/* $OpenBSD: misc.c,v 1.97 2015/04/24 01:36:00 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved. 4 * Copyright (c) 2005,2006 Damien Miller. All rights reserved.
@@ -472,7 +472,7 @@ addargs(arglist *args, char *fmt, ...)
472 } else if (args->num+2 >= nalloc) 472 } else if (args->num+2 >= nalloc)
473 nalloc *= 2; 473 nalloc *= 2;
474 474
475 args->list = xrealloc(args->list, nalloc, sizeof(char *)); 475 args->list = xreallocarray(args->list, nalloc, sizeof(char *));
476 args->nalloc = nalloc; 476 args->nalloc = nalloc;
477 args->list[args->num++] = cp; 477 args->list[args->num++] = cp;
478 args->list[args->num] = NULL; 478 args->list[args->num] = NULL;
diff --git a/mux.c b/mux.c
index f3faaeec9..f05f90c7b 100644
--- a/mux.c
+++ b/mux.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: mux.c,v 1.50 2015/01/20 23:14:00 deraadt Exp $ */ 1/* $OpenBSD: mux.c,v 1.51 2015/04/24 01:36:00 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2002-2008 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2002-2008 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -350,7 +350,7 @@ process_mux_new_session(u_int rid, Channel *c, Buffer *m, Buffer *r)
350 free(cp); 350 free(cp);
351 continue; 351 continue;
352 } 352 }
353 cctx->env = xrealloc(cctx->env, env_len + 2, 353 cctx->env = xreallocarray(cctx->env, env_len + 2,
354 sizeof(*cctx->env)); 354 sizeof(*cctx->env));
355 cctx->env[env_len++] = cp; 355 cctx->env[env_len++] = cp;
356 cctx->env[env_len] = NULL; 356 cctx->env[env_len] = NULL;
diff --git a/readconf.c b/readconf.c
index 9e15f27bb..66090e305 100644
--- a/readconf.c
+++ b/readconf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: readconf.c,v 1.233 2015/03/30 00:00:29 djm Exp $ */ 1/* $OpenBSD: readconf.c,v 1.234 2015/04/24 01:36:00 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -295,7 +295,7 @@ add_local_forward(Options *options, const struct Forward *newfwd)
295 newfwd->listen_path == NULL) 295 newfwd->listen_path == NULL)
296 fatal("Privileged ports can only be forwarded by root."); 296 fatal("Privileged ports can only be forwarded by root.");
297#endif 297#endif
298 options->local_forwards = xrealloc(options->local_forwards, 298 options->local_forwards = xreallocarray(options->local_forwards,
299 options->num_local_forwards + 1, 299 options->num_local_forwards + 1,
300 sizeof(*options->local_forwards)); 300 sizeof(*options->local_forwards));
301 fwd = &options->local_forwards[options->num_local_forwards++]; 301 fwd = &options->local_forwards[options->num_local_forwards++];
@@ -318,7 +318,7 @@ add_remote_forward(Options *options, const struct Forward *newfwd)
318{ 318{
319 struct Forward *fwd; 319 struct Forward *fwd;
320 320
321 options->remote_forwards = xrealloc(options->remote_forwards, 321 options->remote_forwards = xreallocarray(options->remote_forwards,
322 options->num_remote_forwards + 1, 322 options->num_remote_forwards + 1,
323 sizeof(*options->remote_forwards)); 323 sizeof(*options->remote_forwards));
324 fwd = &options->remote_forwards[options->num_remote_forwards++]; 324 fwd = &options->remote_forwards[options->num_remote_forwards++];
diff --git a/scp.c b/scp.c
index 887b014b8..593fe89bd 100644
--- a/scp.c
+++ b/scp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: scp.c,v 1.181 2015/01/16 06:40:12 deraadt Exp $ */ 1/* $OpenBSD: scp.c,v 1.182 2015/04/24 01:36:00 deraadt Exp $ */
2/* 2/*
3 * scp - secure remote copy. This is basically patched BSD rcp which 3 * scp - secure remote copy. This is basically patched BSD rcp which
4 * uses ssh to do the data transfer (instead of using rcmd). 4 * uses ssh to do the data transfer (instead of using rcmd).
@@ -1333,7 +1333,7 @@ allocbuf(BUF *bp, int fd, int blksize)
1333 if (bp->buf == NULL) 1333 if (bp->buf == NULL)
1334 bp->buf = xmalloc(size); 1334 bp->buf = xmalloc(size);
1335 else 1335 else
1336 bp->buf = xrealloc(bp->buf, 1, size); 1336 bp->buf = xreallocarray(bp->buf, 1, size);
1337 memset(bp->buf, 0, size); 1337 memset(bp->buf, 0, size);
1338 bp->cnt = size; 1338 bp->cnt = size;
1339 return (bp); 1339 return (bp);
diff --git a/servconf.c b/servconf.c
index fb1d024ef..d4a48a016 100644
--- a/servconf.c
+++ b/servconf.c
@@ -1,5 +1,5 @@
1 1
2/* $OpenBSD: servconf.c,v 1.263 2015/04/23 04:59:10 dtucker Exp $ */ 2/* $OpenBSD: servconf.c,v 1.264 2015/04/24 01:36:00 deraadt Exp $ */
3/* 3/*
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
5 * All rights reserved 5 * All rights reserved
@@ -1444,7 +1444,7 @@ process_server_config_line(ServerOptions *options, char *line,
1444 len = strlen(p) + 1; 1444 len = strlen(p) + 1;
1445 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') { 1445 while ((arg = strdelim(&cp)) != NULL && *arg != '\0') {
1446 len += 1 + strlen(arg); 1446 len += 1 + strlen(arg);
1447 p = xrealloc(p, 1, len); 1447 p = xreallocarray(p, 1, len);
1448 strlcat(p, " ", len); 1448 strlcat(p, " ", len);
1449 strlcat(p, arg, len); 1449 strlcat(p, arg, len);
1450 } 1450 }
diff --git a/session.c b/session.c
index 54bac36a8..5a64715e2 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: session.c,v 1.277 2015/01/16 06:40:12 deraadt Exp $ */ 1/* $OpenBSD: session.c,v 1.278 2015/04/24 01:36:00 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved 4 * All rights reserved
@@ -997,7 +997,7 @@ child_set_env(char ***envp, u_int *envsizep, const char *name,
997 if (envsize >= 1000) 997 if (envsize >= 1000)
998 fatal("child_set_env: too many env vars"); 998 fatal("child_set_env: too many env vars");
999 envsize += 50; 999 envsize += 50;
1000 env = (*envp) = xrealloc(env, envsize, sizeof(char *)); 1000 env = (*envp) = xreallocarray(env, envsize, sizeof(char *));
1001 *envsizep = envsize; 1001 *envsizep = envsize;
1002 } 1002 }
1003 /* Need to set the NULL pointer at end of array beyond the new slot. */ 1003 /* Need to set the NULL pointer at end of array beyond the new slot. */
@@ -1914,7 +1914,7 @@ session_new(void)
1914 return NULL; 1914 return NULL;
1915 debug2("%s: allocate (allocated %d max %d)", 1915 debug2("%s: allocate (allocated %d max %d)",
1916 __func__, sessions_nalloc, options.max_sessions); 1916 __func__, sessions_nalloc, options.max_sessions);
1917 tmp = xrealloc(sessions, sessions_nalloc + 1, 1917 tmp = xreallocarray(sessions, sessions_nalloc + 1,
1918 sizeof(*sessions)); 1918 sizeof(*sessions));
1919 if (tmp == NULL) { 1919 if (tmp == NULL) {
1920 error("%s: cannot allocate %d sessions", 1920 error("%s: cannot allocate %d sessions",
@@ -2241,7 +2241,7 @@ session_env_req(Session *s)
2241 for (i = 0; i < options.num_accept_env; i++) { 2241 for (i = 0; i < options.num_accept_env; i++) {
2242 if (match_pattern(name, options.accept_env[i])) { 2242 if (match_pattern(name, options.accept_env[i])) {
2243 debug2("Setting env %d: %s=%s", s->num_env, name, val); 2243 debug2("Setting env %d: %s=%s", s->num_env, name, val);
2244 s->env = xrealloc(s->env, s->num_env + 1, 2244 s->env = xreallocarray(s->env, s->num_env + 1,
2245 sizeof(*s->env)); 2245 sizeof(*s->env));
2246 s->env[s->num_env].name = name; 2246 s->env[s->num_env].name = name;
2247 s->env[s->num_env].val = val; 2247 s->env[s->num_env].val = val;
diff --git a/sftp-client.c b/sftp-client.c
index 80f4805cb..32deaa714 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-client.c,v 1.117 2015/01/20 23:14:00 deraadt Exp $ */ 1/* $OpenBSD: sftp-client.c,v 1.118 2015/04/24 01:36:00 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -621,7 +621,7 @@ do_lsreaddir(struct sftp_conn *conn, const char *path, int print_flag,
621 error("Server sent suspect path \"%s\" " 621 error("Server sent suspect path \"%s\" "
622 "during readdir of \"%s\"", filename, path); 622 "during readdir of \"%s\"", filename, path);
623 } else if (dir) { 623 } else if (dir) {
624 *dir = xrealloc(*dir, ents + 2, sizeof(**dir)); 624 *dir = xreallocarray(*dir, ents + 2, sizeof(**dir));
625 (*dir)[ents] = xcalloc(1, sizeof(***dir)); 625 (*dir)[ents] = xcalloc(1, sizeof(***dir));
626 (*dir)[ents]->filename = xstrdup(filename); 626 (*dir)[ents]->filename = xstrdup(filename);
627 (*dir)[ents]->longname = xstrdup(longname); 627 (*dir)[ents]->longname = xstrdup(longname);
diff --git a/sftp-server.c b/sftp-server.c
index 85fa5acce..d1831bf8d 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-server.c,v 1.105 2015/01/20 23:14:00 deraadt Exp $ */ 1/* $OpenBSD: sftp-server.c,v 1.106 2015/04/24 01:36:01 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2000-2004 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000-2004 Markus Friedl. All rights reserved.
4 * 4 *
@@ -309,7 +309,7 @@ handle_new(int use, const char *name, int fd, int flags, DIR *dirp)
309 if (num_handles + 1 <= num_handles) 309 if (num_handles + 1 <= num_handles)
310 return -1; 310 return -1;
311 num_handles++; 311 num_handles++;
312 handles = xrealloc(handles, num_handles, sizeof(Handle)); 312 handles = xreallocarray(handles, num_handles, sizeof(Handle));
313 handle_unused(num_handles - 1); 313 handle_unused(num_handles - 1);
314 } 314 }
315 315
@@ -1062,7 +1062,7 @@ process_readdir(u_int32_t id)
1062 while ((dp = readdir(dirp)) != NULL) { 1062 while ((dp = readdir(dirp)) != NULL) {
1063 if (count >= nstats) { 1063 if (count >= nstats) {
1064 nstats *= 2; 1064 nstats *= 2;
1065 stats = xrealloc(stats, nstats, sizeof(Stat)); 1065 stats = xreallocarray(stats, nstats, sizeof(Stat));
1066 } 1066 }
1067/* XXX OVERFLOW ? */ 1067/* XXX OVERFLOW ? */
1068 snprintf(pathname, sizeof pathname, "%s%s%s", path, 1068 snprintf(pathname, sizeof pathname, "%s%s%s", path,
diff --git a/ssh-agent.c b/ssh-agent.c
index aeda656ac..2eb3322a0 100644
--- a/ssh-agent.c
+++ b/ssh-agent.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-agent.c,v 1.199 2015/03/04 21:12:59 djm Exp $ */ 1/* $OpenBSD: ssh-agent.c,v 1.200 2015/04/24 01:36:01 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -929,7 +929,7 @@ new_socket(sock_type type, int fd)
929 } 929 }
930 old_alloc = sockets_alloc; 930 old_alloc = sockets_alloc;
931 new_alloc = sockets_alloc + 10; 931 new_alloc = sockets_alloc + 10;
932 sockets = xrealloc(sockets, new_alloc, sizeof(sockets[0])); 932 sockets = xreallocarray(sockets, new_alloc, sizeof(sockets[0]));
933 for (i = old_alloc; i < new_alloc; i++) 933 for (i = old_alloc; i < new_alloc; i++)
934 sockets[i].type = AUTH_UNUSED; 934 sockets[i].type = AUTH_UNUSED;
935 sockets_alloc = new_alloc; 935 sockets_alloc = new_alloc;
diff --git a/ssh-keygen.c b/ssh-keygen.c
index d3c412283..ad9f3026b 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.269 2015/04/17 13:19:22 djm Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.270 2015/04/24 01:36:01 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1592,7 +1592,7 @@ do_ca_sign(struct passwd *pw, int argc, char **argv)
1592 otmp = tmp = xstrdup(cert_principals); 1592 otmp = tmp = xstrdup(cert_principals);
1593 plist = NULL; 1593 plist = NULL;
1594 for (; (cp = strsep(&tmp, ",")) != NULL; n++) { 1594 for (; (cp = strsep(&tmp, ",")) != NULL; n++) {
1595 plist = xrealloc(plist, n + 1, sizeof(*plist)); 1595 plist = xreallocarray(plist, n + 1, sizeof(*plist));
1596 if (*(plist[n] = xstrdup(cp)) == '\0') 1596 if (*(plist[n] = xstrdup(cp)) == '\0')
1597 fatal("Empty principal name"); 1597 fatal("Empty principal name");
1598 } 1598 }
diff --git a/ssh-pkcs11.c b/ssh-pkcs11.c
index c3a112fa1..f4971ad8a 100644
--- a/ssh-pkcs11.c
+++ b/ssh-pkcs11.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-pkcs11.c,v 1.17 2015/02/03 08:07:20 deraadt Exp $ */ 1/* $OpenBSD: ssh-pkcs11.c,v 1.18 2015/04/24 01:36:01 deraadt Exp $ */
2/* 2/*
3 * Copyright (c) 2010 Markus Friedl. All rights reserved. 3 * Copyright (c) 2010 Markus Friedl. All rights reserved.
4 * 4 *
@@ -527,7 +527,7 @@ pkcs11_fetch_keys_filter(struct pkcs11_provider *p, CK_ULONG slotidx,
527 sshkey_free(key); 527 sshkey_free(key);
528 } else { 528 } else {
529 /* expand key array and add key */ 529 /* expand key array and add key */
530 *keysp = xrealloc(*keysp, *nkeys + 1, 530 *keysp = xreallocarray(*keysp, *nkeys + 1,
531 sizeof(struct sshkey *)); 531 sizeof(struct sshkey *));
532 (*keysp)[*nkeys] = key; 532 (*keysp)[*nkeys] = key;
533 *nkeys = *nkeys + 1; 533 *nkeys = *nkeys + 1;
diff --git a/xmalloc.c b/xmalloc.c
index cd59dc2e5..98cbf8776 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: xmalloc.c,v 1.31 2015/02/06 23:21:59 millert Exp $ */ 1/* $OpenBSD: xmalloc.c,v 1.32 2015/04/24 01:36:01 deraadt Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -56,22 +56,14 @@ xcalloc(size_t nmemb, size_t size)
56} 56}
57 57
58void * 58void *
59xrealloc(void *ptr, size_t nmemb, size_t size) 59xreallocarray(void *ptr, size_t nmemb, size_t size)
60{ 60{
61 void *new_ptr; 61 void *new_ptr;
62 size_t new_size = nmemb * size;
63 62
64 if (new_size == 0) 63 new_ptr = reallocarray(ptr, nmemb, size);
65 fatal("xrealloc: zero size");
66 if (SIZE_MAX / nmemb < size)
67 fatal("xrealloc: nmemb * size > SIZE_MAX");
68 if (ptr == NULL)
69 new_ptr = malloc(new_size);
70 else
71 new_ptr = realloc(ptr, new_size);
72 if (new_ptr == NULL) 64 if (new_ptr == NULL)
73 fatal("xrealloc: out of memory (new_size %zu bytes)", 65 fatal("xreallocarray: out of memory (%zu elements of %zu bytes)",
74 new_size); 66 nmemb, size);
75 return new_ptr; 67 return new_ptr;
76} 68}
77 69
diff --git a/xmalloc.h b/xmalloc.h
index 261dfd612..2bec77ba8 100644
--- a/xmalloc.h
+++ b/xmalloc.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: xmalloc.h,v 1.14 2013/05/17 00:13:14 djm Exp $ */ 1/* $OpenBSD: xmalloc.h,v 1.15 2015/04/24 01:36:01 deraadt Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -18,7 +18,7 @@
18 18
19void *xmalloc(size_t); 19void *xmalloc(size_t);
20void *xcalloc(size_t, size_t); 20void *xcalloc(size_t, size_t);
21void *xrealloc(void *, size_t, size_t); 21void *xreallocarray(void *, size_t, size_t);
22char *xstrdup(const char *); 22char *xstrdup(const char *);
23int xasprintf(char **, const char *, ...) 23int xasprintf(char **, const char *, ...)
24 __attribute__((__format__ (printf, 2, 3))) 24 __attribute__((__format__ (printf, 2, 3)))