Skip to content

Commit

Permalink
more shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip Pizlo committed Feb 24, 2024
1 parent cd6a3e6 commit 4151f6f
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 80 deletions.
7 changes: 2 additions & 5 deletions auth-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ handle_permit(const char **optsp, int allow_bare_port,
/* XXX - add streamlocal support */
free(tmp);
/* Record it */
if ((permits = recallocarray(permits, npermits, npermits + 1,
sizeof(*permits))) == NULL) {
if ((permits = zrealloc(zrestrict(permits, typeof(*permits), npermits), typeof(*permits), npermits + 1)) == NULL) {
free(opt);
/* NB. don't update *permitsp if alloc fails */
*errstrp = "memory allocation failed";
Expand Down Expand Up @@ -437,9 +436,7 @@ sshauthopt_parse(const char *opts, const char **errstrp)
if (i >= ret->nenv) {
/* Append it. */
oarray = ret->env;
if ((ret->env = recallocarray(ret->env,
ret->nenv, ret->nenv + 1,
sizeof(*ret->env))) == NULL) {
if ((ret->env = zrealloc(zrestrict(ret->env, typeof(*ret->env), ret->nenv), typeof(*ret->env), ret->nenv + 1)) == NULL) {
free(opt);
/* put it back for cleanup */
ret->env = oarray;
Expand Down
3 changes: 1 addition & 2 deletions auth2.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,7 @@ auth2_record_key(Authctxt *authctxt, int authenticated,
if ((r = sshkey_from_private(key, &dup)) != 0)
fatal_fr(r, "copy key");
if (authctxt->nprev_keys >= INT_MAX ||
(tmp = recallocarray(authctxt->prev_keys, authctxt->nprev_keys,
authctxt->nprev_keys + 1, sizeof(*authctxt->prev_keys))) == NULL)
(tmp = zrealloc(zrestrict(authctxt->prev_keys, typeof(*authctxt->prev_keys), authctxt->nprev_keys), typeof(*authctxt->prev_keys), authctxt->nprev_keys + 1)) == NULL)
fatal_f("reallocarray failed");
authctxt->prev_keys = tmp;
authctxt->prev_keys[authctxt->nprev_keys] = dup;
Expand Down
13 changes: 5 additions & 8 deletions channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ channel_add_timeout(struct ssh *ssh, const char *type_pattern,

debug2_f("channel type \"%s\" timeout %d seconds",
type_pattern, timeout_secs);
sc->timeouts = xrecallocarray(sc->timeouts, sc->ntimeouts,
sc->ntimeouts + 1, sizeof(*sc->timeouts));
sc->timeouts = zrealloc(zrestrict(sc->timeouts, typeof(*sc->timeouts), sc->ntimeouts), typeof(*sc->timeouts), sc->ntimeouts + 1);
sc->timeouts[sc->ntimeouts].type_pattern = xstrdup(type_pattern);
sc->timeouts[sc->ntimeouts].timeout_secs = timeout_secs;
sc->ntimeouts++;
Expand Down Expand Up @@ -473,8 +472,7 @@ channel_new(struct ssh *ssh, char *ctype, int type, int rfd, int wfd, int efd,
if (sc->channels_alloc > CHANNELS_MAX_CHANNELS)
fatal_f("internal error: channels_alloc %d too big",
sc->channels_alloc);
sc->channels = xrecallocarray(sc->channels, sc->channels_alloc,
sc->channels_alloc + 10, sizeof(*sc->channels));
sc->channels = zrealloc(zrestrict(sc->channels, typeof(*sc->channels), sc->channels_alloc), typeof(*sc->channels), sc->channels_alloc + 10);
sc->channels_alloc += 10;
debug2("channel: expanding %d", sc->channels_alloc);
}
Expand Down Expand Up @@ -650,7 +648,7 @@ permission_set_add(struct ssh *ssh, int who, int where,
if (*npermp >= INT_MAX)
fatal_f("%s overflow", fwd_ident(who, where));

*permp = xrecallocarray(*permp, *npermp, *npermp + 1, sizeof(**permp));
*permp = zrealloc(zrestrict(*permp, typeof(**permp), *npermp), typeof(**permp), *npermp + 1);
n = (*npermp)++;
#define MAYBE_DUP(s) ((s == NULL) ? NULL : xstrdup(s))
(*permp)[n].host_to_connect = MAYBE_DUP(host_to_connect);
Expand Down Expand Up @@ -2774,8 +2772,7 @@ channel_prepare_poll(struct ssh *ssh, struct pollfd **pfdp, u_int *npfd_allocp,
fatal_f("too many channels"); /* shouldn't happen */
npfd += sc->channels_alloc * 4;
if (npfd > *npfd_allocp) {
*pfdp = xrecallocarray(*pfdp, *npfd_allocp,
npfd, sizeof(**pfdp));
*pfdp = zrealloc(zrestrict(*pfdp, typeof(**pfdp), *npfd_allocp), typeof(**pfdp), npfd);
*npfd_allocp = npfd;
}
*npfd_activep = npfd_reserved;
Expand Down Expand Up @@ -4508,7 +4505,7 @@ channel_clear_permission(struct ssh *ssh, int who, int where)
u_int *npermp;

permission_set_get_array(ssh, who, where, &permp, &npermp);
*permp = xrecallocarray(*permp, *npermp, 0, sizeof(**permp));
*permp = zrealloc(zrestrict(*permp, typeof(**permp), *npermp), typeof(**permp), 0);
*npermp = 0;
}

Expand Down
6 changes: 2 additions & 4 deletions clientloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -2172,8 +2172,7 @@ hostkeys_find(struct hostkey_foreach_line *l, void *_ctx)
/* This line contained a key that not offered by the server */
debug3_f("deprecated %s key at %s:%ld", sshkey_ssh_name(l->key),
l->path, l->linenum);
if ((tmp = recallocarray(ctx->old_keys, ctx->nold, ctx->nold + 1,
sizeof(*ctx->old_keys))) == NULL)
if ((tmp = zrealloc(zrestrict(ctx->old_keys, typeof(*ctx->old_keys), ctx->nold), typeof(*ctx->old_keys), ctx->nold + 1)) == NULL)
fatal_f("recallocarray failed nold = %zu", ctx->nold);
ctx->old_keys = tmp;
ctx->old_keys[ctx->nold++] = l->key;
Expand Down Expand Up @@ -2524,8 +2523,7 @@ client_input_hostkeys(struct ssh *ssh)
}
}
/* Key is good, record it */
if ((tmp = recallocarray(ctx->keys, ctx->nkeys, ctx->nkeys + 1,
sizeof(*ctx->keys))) == NULL)
if ((tmp = zrealloc(zrestrict(ctx->keys, typeof(*ctx->keys), ctx->nkeys), typeof(*ctx->keys), ctx->nkeys + 1)) == NULL)
fatal_f("recallocarray failed nkeys = %zu",
ctx->nkeys);
ctx->keys = tmp;
Expand Down
15 changes: 14 additions & 1 deletion fixalloc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
# | match |
# "zalloc(typeof(*#{$1}), #{$2})"
#}
contents.gsub!(/xzalloc/) { | match | "zalloc" }
#contents.gsub!(/xzalloc/) { | match | "zalloc" }
#contents.gsub!(/xrecallocarray\(([^\n]+),\s+([^\n]+),\s+([^\n]+),\s+sizeof\(([a-zA-Z0-9_*]+)\)\)/) {
# | match |
# "zrealloc(zrestrict(#{$1}, typeof(#{$4}), #{$2}), typeof(#{$4}), #{$3})"
#}
#contents.gsub!(/recallocarray\(([^\n]+),\s+([^\n]+),\s+([^\n]+),\s+sizeof\(([a-zA-Z0-9_*]+)\)\)/) {
# | match |
# "zrealloc(zrestrict(#{$1}, typeof(#{$4}), #{$2}), typeof(#{$4}), #{$3})"
#}
#contents.gsub!(/recallocarray\(([^\n]+),\s+([^\n]+),\s+([^\n]+),\s+sizeof\(([a-zA-Z0-9_*>-]+)\)\)/) {
# | match |
# "zrealloc(zrestrict(#{$1}, typeof(#{$4}), #{$2}), typeof(#{$4}), #{$3})"
#}
contents.gsub!(/xzrealloc/) { | match | "zrealloc" }
IO::write(filename, contents)
}
3 changes: 1 addition & 2 deletions hostfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ record_hostkey(struct hostkey_foreach_line *l, void *_ctx)
l->marker == MRK_NONE ? "" :
(l->marker == MRK_CA ? "ca " : "revoked "),
sshkey_type(l->key), l->path, l->linenum);
if ((tmp = recallocarray(hostkeys->entries, hostkeys->num_entries,
hostkeys->num_entries + 1, sizeof(*hostkeys->entries))) == NULL)
if ((tmp = zrealloc(zrestrict(hostkeys->entries, typeof(*hostkeys->entries), hostkeys->num_entries), typeof(*hostkeys->entries), hostkeys->num_entries + 1)) == NULL)
return SSH_ERR_ALLOC_FAIL;
hostkeys->entries = tmp;
hostkeys->entries[hostkeys->num_entries].host = xstrdup(ctx->host);
Expand Down
3 changes: 1 addition & 2 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ log_verbose_add(const char *s)
char **tmp;

/* Ignore failures here */
if ((tmp = recallocarray(log_verbose, nlog_verbose, nlog_verbose + 1,
sizeof(*log_verbose))) != NULL) {
if ((tmp = zrealloc(zrestrict(log_verbose, typeof(*log_verbose), nlog_verbose), typeof(*log_verbose), nlog_verbose + 1)) != NULL) {
log_verbose = tmp;
if ((log_verbose[nlog_verbose] = strdup(s)) != NULL)
nlog_verbose++;
Expand Down
5 changes: 2 additions & 3 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2627,12 +2627,11 @@ opt_array_append2(const char *file, const int line, const char *directive,
fatal("%s line %d: Too many %s entries", file, line, directive);

if (iarray != NULL) {
*iarray = xrecallocarray(*iarray, *lp, *lp + 1,
sizeof(**iarray));
*iarray = zrealloc(zrestrict(*iarray, typeof(**iarray), *lp), typeof(**iarray), *lp + 1);
(*iarray)[*lp] = i;
}

*array = xrecallocarray(*array, *lp, *lp + 1, sizeof(**array));
*array = zrealloc(zrestrict(*array, typeof(**array), *lp), typeof(**array), *lp + 1);
(*array)[*lp] = xstrdup(s);
(*lp)++;
}
Expand Down
7 changes: 2 additions & 5 deletions readconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,7 @@ rm_env(Options *options, const char *arg, const char *filename, int linenum)
/* NB. don't increment i */
}
if (onum_send_env != options->num_send_env) {
options->send_env = xrecallocarray(options->send_env,
onum_send_env, options->num_send_env,
sizeof(*options->send_env));
options->send_env = zrealloc(zrestrict(options->send_env, typeof(*options->send_env), onum_send_env), typeof(*options->send_env), options->num_send_env);
}
}

Expand Down Expand Up @@ -1605,8 +1603,7 @@ process_config_line_depth(Options *options, struct passwd *pw, const char *host,
}
i++;
if (*activep && *uintptr == 0) {
*cppptr = xrecallocarray(*cppptr, *uintptr,
*uintptr + 1, sizeof(**cppptr));
*cppptr = zrealloc(zrestrict(*cppptr, typeof(**cppptr), *uintptr), typeof(**cppptr), *uintptr + 1);
(*cppptr)[(*uintptr)++] = xstrdup(arg);
}
}
Expand Down
2 changes: 1 addition & 1 deletion regress/unittests/authopt/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ commasplit(const char *s, size_t *np)
ocp = cp = strdup(s);
ASSERT_PTR_NE(cp, NULL);
for (n = 0; (cp2 = strsep(&cp, ",")) != NULL;) {
ret = recallocarray(ret, n, n + 1, sizeof(*ret));
ret = zrealloc(zrestrict(ret, typeof(*ret), n), typeof(*ret), n + 1);
ASSERT_PTR_NE(ret, NULL);
cp2 = strdup(cp2);
ASSERT_PTR_NE(cp2, NULL);
Expand Down
4 changes: 1 addition & 3 deletions servconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,7 @@ add_one_listen_addr(ServerOptions *options, const char *addr,
/* No entry for this rdomain; allocate one */
if (i >= INT_MAX)
fatal_f("too many listen addresses");
options->listen_addrs = xrecallocarray(options->listen_addrs,
options->num_listen_addrs, options->num_listen_addrs + 1,
sizeof(*options->listen_addrs));
options->listen_addrs = zrealloc(zrestrict(options->listen_addrs, typeof(*options->listen_addrs), options->num_listen_addrs), typeof(*options->listen_addrs), options->num_listen_addrs + 1);
i = options->num_listen_addrs++;
if (rdomain != NULL)
options->listen_addrs[i].rdomain = xstrdup(rdomain);
Expand Down
6 changes: 2 additions & 4 deletions session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1746,8 +1746,7 @@ session_new(void)
return NULL;
debug2_f("allocate (allocated %d max %d)",
sessions_nalloc, options.max_sessions);
tmp = xrecallocarray(sessions, sessions_nalloc,
sessions_nalloc + 1, sizeof(*sessions));
tmp = zrealloc(zrestrict(sessions, typeof(*sessions), sessions_nalloc), typeof(*sessions), sessions_nalloc + 1);
if (tmp == NULL) {
error_f("cannot allocate %d sessions",
sessions_nalloc + 1);
Expand Down Expand Up @@ -2096,8 +2095,7 @@ session_env_req(struct ssh *ssh, Session *s)
for (i = 0; i < options.num_accept_env; i++) {
if (match_pattern(name, options.accept_env[i])) {
debug2("Setting env %d: %s=%s", s->num_env, name, val);
s->env = xrecallocarray(s->env, s->num_env,
s->num_env + 1, sizeof(*s->env));
s->env = zrealloc(zrestrict(s->env, typeof(*s->env), s->num_env), typeof(*s->env), s->num_env + 1);
s->env[s->num_env].name = name;
s->env[s->num_env].val = val;
s->num_env++;
Expand Down
4 changes: 2 additions & 2 deletions sftp-usergroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ collect_ids_from_glob(glob_t *g, int user, u_int **idsp, u_int *nidsp)
}
if (has_id(id, ids, n))
continue;
ids = xrecallocarray(ids, n, n + 1, sizeof(*ids));
ids = zrealloc(zrestrict(ids, typeof(*ids), n), typeof(*ids), n + 1);
ids[n++] = id;
}
*idsp = ids;
Expand Down Expand Up @@ -203,7 +203,7 @@ collect_ids_from_dirents(SFTP_DIRENT **d, int user, u_int **idsp, u_int *nidsp)
}
if (has_id(id, ids, n))
continue;
ids = xrecallocarray(ids, n, n + 1, sizeof(*ids));
ids = zrealloc(zrestrict(ids, typeof(*ids), n), typeof(*ids), n + 1);
ids[n++] = id;
}
*idsp = ids;
Expand Down
3 changes: 1 addition & 2 deletions sk-usbhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1397,8 +1397,7 @@ read_rks(struct sk_usbhid *sk, const char *pin,
goto out;
}
/* append */
if ((tmp = recallocarray(*rksp, *nrksp, (*nrksp) + 1,
sizeof(**rksp))) == NULL) {
if ((tmp = zrealloc(zrestrict(*rksp, typeof(**rksp), *nrksp), typeof(**rksp), (*nrksp) + 1)) == NULL) {
skdebug(__func__, "alloc rksp");
goto out;
}
Expand Down
13 changes: 5 additions & 8 deletions ssh-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ stringlist_append(char ***listp, const char *s)
else {
for (i = 0; (*listp)[i] != NULL; i++)
; /* count */
*listp = xrecallocarray(*listp, i + 1, i + 2, sizeof(**listp));
*listp = zrealloc(zrestrict(*listp, typeof(**listp), i + 1), typeof(**listp), i + 2);
}
(*listp)[i] = xstrdup(s);
}
Expand Down Expand Up @@ -735,10 +735,8 @@ parse_dest_constraint_hop(const char *s, struct dest_constraint_hop *dch,
user == NULL ? "": user, user == NULL ? "" : "@",
host, sshkey_type(hke->key), want_ca ? "CA " : "",
hke->file, hke->line, dch->nkeys);
dch->keys = xrecallocarray(dch->keys, dch->nkeys,
dch->nkeys + 1, sizeof(*dch->keys));
dch->key_is_ca = xrecallocarray(dch->key_is_ca, dch->nkeys,
dch->nkeys + 1, sizeof(*dch->key_is_ca));
dch->keys = zrealloc(zrestrict(dch->keys, typeof(*dch->keys), dch->nkeys), typeof(*dch->keys), dch->nkeys + 1);
dch->key_is_ca = zrealloc(zrestrict(dch->key_is_ca, typeof(*dch->key_is_ca), dch->nkeys), typeof(*dch->key_is_ca), dch->nkeys + 1);
if ((r = sshkey_from_private(hke->key,
&(dch->keys[dch->nkeys]))) != 0)
fatal_fr(r, "sshkey_from_private");
Expand Down Expand Up @@ -780,7 +778,7 @@ parse_dest_constraint(const char *s, struct dest_constraint ***dcp,
dc->from.hostname ? dc->from.hostname : "(ORIGIN)", dc->from.nkeys,
dc->to.user ? dc->to.user : "", dc->to.user ? "@" : "",
dc->to.hostname ? dc->to.hostname : "(ANY)", dc->to.nkeys);
*dcp = xrecallocarray(*dcp, *ndcp, *ndcp + 1, sizeof(**dcp));
*dcp = zrealloc(zrestrict(*dcp, typeof(**dcp), *ndcp), typeof(**dcp), *ndcp + 1);
(*dcp)[(*ndcp)++] = dc;
free(os);
}
Expand Down Expand Up @@ -990,8 +988,7 @@ main(int argc, char **argv)
for (i = 0; i < argc; i++) {
if ((r = sshkey_load_public(argv[i], &k, NULL)) != 0)
fatal_fr(r, "load certificate %s", argv[i]);
certs = xrecallocarray(certs, ncerts, ncerts + 1,
sizeof(*certs));
certs = zrealloc(zrestrict(certs, typeof(*certs), ncerts), typeof(*certs), ncerts + 1);
debug2("%s: %s", argv[i], sshkey_ssh_name(k));
certs[ncerts++] = k;
}
Expand Down
17 changes: 6 additions & 11 deletions ssh-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,10 +1092,8 @@ parse_dest_constraint_hop(struct sshbuf *b, struct dest_constraint_hop *dch)
dch->user = NULL;
}
while (sshbuf_len(b) != 0) {
dch->keys = xrecallocarray(dch->keys, dch->nkeys,
dch->nkeys + 1, sizeof(*dch->keys));
dch->key_is_ca = xrecallocarray(dch->key_is_ca, dch->nkeys,
dch->nkeys + 1, sizeof(*dch->key_is_ca));
dch->keys = zrealloc(zrestrict(dch->keys, typeof(*dch->keys), dch->nkeys), typeof(*dch->keys), dch->nkeys + 1);
dch->key_is_ca = zrealloc(zrestrict(dch->key_is_ca, typeof(*dch->key_is_ca), dch->nkeys), typeof(*dch->key_is_ca), dch->nkeys + 1);
if ((r = sshkey_froms(b, &k)) != 0 ||
(r = sshbuf_get_u8(b, &key_is_ca)) != 0)
goto out;
Expand Down Expand Up @@ -1215,8 +1213,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp,
error_f("too many %s constraints", ext_name);
goto out;
}
*dcsp = xrecallocarray(*dcsp, *ndcsp, *ndcsp + 1,
sizeof(**dcsp));
*dcsp = zrealloc(zrestrict(*dcsp, typeof(**dcsp), *ndcsp), typeof(**dcsp), *ndcsp + 1);
if ((r = parse_dest_constraint(b,
*dcsp + (*ndcsp)++)) != 0)
goto out; /* error already logged */
Expand All @@ -1243,8 +1240,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp,
error_f("too many %s constraints", ext_name);
goto out;
}
*certs = xrecallocarray(*certs, *ncerts, *ncerts + 1,
sizeof(**certs));
*certs = zrealloc(zrestrict(*certs, typeof(**certs), *ncerts), typeof(**certs), *ncerts + 1);
if ((r = sshkey_froms(b, &k)) != 0) {
error_fr(r, "parse key");
goto out;
Expand Down Expand Up @@ -1739,8 +1735,7 @@ process_ext_session_bind(SocketEntry *e)
error_f("too many session IDs recorded");
goto out;
}
e->session_ids = xrecallocarray(e->session_ids, e->nsession_ids,
e->nsession_ids + 1, sizeof(*e->session_ids));
e->session_ids = zrealloc(zrestrict(e->session_ids, typeof(*e->session_ids), e->nsession_ids), typeof(*e->session_ids), e->nsession_ids + 1);
i = e->nsession_ids++;
debug_f("recorded %s %s (slot %zu of %d)", sshkey_type(key), fp, i,
AGENT_MAX_SESSION_IDS);
Expand Down Expand Up @@ -2082,7 +2077,7 @@ prepare_poll(struct pollfd **pfdp, size_t *npfdp, int *timeoutp, u_int maxfds)
}
}
if (npfd != *npfdp &&
(pfd = recallocarray(pfd, *npfdp, npfd, sizeof(*pfd))) == NULL)
(pfd = zrealloc(zrestrict(pfd, typeof(*pfd), *npfdp), typeof(*pfd), npfd)) == NULL)
fatal_f("recallocarray failed");
*pfdp = pfd;
*npfdp = npfd;
Expand Down
3 changes: 1 addition & 2 deletions ssh-keygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -3466,8 +3466,7 @@ main(int argc, char **argv)
check_krl = 1;
break;
case 'O':
opts = xrecallocarray(opts, nopts, nopts + 1,
sizeof(*opts));
opts = zrealloc(zrestrict(opts, typeof(*opts), nopts), typeof(*opts), nopts + 1);
opts[nopts++] = xstrdup(optarg);
break;
case 'Z':
Expand Down
6 changes: 2 additions & 4 deletions ssh-pkcs11-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ helper_free(struct helper *helper)
helpers[i - 1] = helpers[i];
}
if (found) {
helpers = xrecallocarray(helpers, nhelpers,
nhelpers - 1, sizeof(*helpers));
helpers = zrealloc(zrestrict(helpers, typeof(*helpers), nhelpers), typeof(*helpers), nhelpers - 1);
nhelpers--;
}
free(helper->path);
Expand Down Expand Up @@ -573,8 +572,7 @@ pkcs11_start_helper(const char *path)
helper->pid = pid;
debug3_f("helper %zu for \"%s\" on fd %d pid %ld", nhelpers,
helper->path, helper->fd, (long)helper->pid);
helpers = xrecallocarray(helpers, nhelpers,
nhelpers + 1, sizeof(*helpers));
helpers = zrealloc(zrestrict(helpers, typeof(*helpers), nhelpers), typeof(*helpers), nhelpers + 1);
helpers[nhelpers++] = helper;
return helper;
}
Expand Down
3 changes: 1 addition & 2 deletions ssh-sk-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,7 @@ sshsk_load_resident(const char *provider_path, const char *device,
srk->user_id_len = userid_len;
userid = NULL;
userid_len = 0;
if ((tmp = recallocarray(srks, nsrks, nsrks + 1,
sizeof(*srks))) == NULL) {
if ((tmp = zrealloc(zrestrict(srks, typeof(*srks), nsrks), typeof(*srks), nsrks + 1)) == NULL) {
error_f("recallocarray keys failed");
goto out;
}
Expand Down
3 changes: 1 addition & 2 deletions ssh-sk.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,7 @@ sshsk_load_resident(const char *provider_path, const char *device,
}
memcpy(srk->user_id, rks[i]->user_id, rks[i]->user_id_len);
srk->user_id_len = rks[i]->user_id_len;
if ((tmp = recallocarray(srks, nsrks, nsrks + 1,
sizeof(*tmp))) == NULL) {
if ((tmp = zrealloc(zrestrict(srks, typeof(*tmp), nsrks), typeof(*tmp), nsrks + 1)) == NULL) {
error_f("recallocarray failed");
r = SSH_ERR_ALLOC_FAIL;
goto out;
Expand Down
3 changes: 1 addition & 2 deletions sshconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,7 @@ hostkeys_find_by_key_cb(struct hostkey_foreach_line *l, void *_ctx)
return 0;
path = try_tilde_unexpand(l->path);
debug_f("found matching key in %s:%lu", path, l->linenum);
ctx->names = xrecallocarray(ctx->names,
ctx->nnames, ctx->nnames + 1, sizeof(*ctx->names));
ctx->names = zrealloc(zrestrict(ctx->names, typeof(*ctx->names), ctx->nnames), typeof(*ctx->names), ctx->nnames + 1);
xasprintf(&ctx->names[ctx->nnames], "%s:%lu: %s", path, l->linenum,
strncmp(l->hosts, HASH_MAGIC, strlen(HASH_MAGIC)) == 0 ?
"[hashed name]" : l->hosts);
Expand Down
Loading

0 comments on commit 4151f6f

Please sign in to comment.