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 4151f6f commit 010801d
Show file tree
Hide file tree
Showing 26 changed files with 55 additions and 51 deletions.
4 changes: 2 additions & 2 deletions auth-bsdauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ bsdauth_query(void *ctx, char **name, char **infotxt,
*name = xstrdup("");
*infotxt = xstrdup("");
*numprompts = 1;
*prompts = xcalloc(*numprompts, sizeof(char *));
*echo_on = xcalloc(*numprompts, sizeof(u_int));
*prompts = zalloc(char *, *numprompts);
*echo_on = zalloc(u_int, *numprompts);
(*prompts)[0] = xstrdup(challenge);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions auth2-chall.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ kbdint_alloc(const char *devs)
remove_kbdint_device("pam");
#endif

kbdintctxt = xcalloc(1, sizeof(KbdintAuthctxt));
kbdintctxt = zalloc(KbdintAuthctxt, 1);
if (strcmp(devs, "") == 0) {
if ((b = sshbuf_new()) == NULL)
fatal_f("sshbuf_new failed");
Expand Down Expand Up @@ -313,7 +313,7 @@ input_userauth_info_response(int type, u_int32_t seq, struct ssh *ssh)
if (nresp > 100)
fatal_f("too many replies");
if (nresp > 0) {
response = xcalloc(nresp, sizeof(char *));
response = zalloc(char *, nresp);
for (i = 0; i < nresp; i++) {
if ((r = sshpkt_get_cstring(ssh, &response[i], NULL)) != 0)
fatal_fr(r, "parse response");
Expand Down
4 changes: 2 additions & 2 deletions channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ channel_new(struct ssh *ssh, char *ctype, int type, int rfd, int wfd, int efd,
debug2("channel: expanding %d", sc->channels_alloc);
}
/* Initialize and return new channel. */
c = sc->channels[found] = xcalloc(1, sizeof(Channel));
c = sc->channels[found] = zalloc(Channel, 1);
if ((c->input = sshbuf_new()) == NULL ||
(c->output = sshbuf_new()) == NULL ||
(c->extended = sshbuf_new()) == NULL)
Expand Down Expand Up @@ -5054,7 +5054,7 @@ x11_create_display_inet(struct ssh *ssh, int x11_display_offset,
}

/* Allocate a channel for each socket. */
*chanids = xcalloc(num_socks + 1, sizeof(**chanids));
*chanids = zalloc(typeof(**chanids), num_socks + 1);
for (n = 0; n < num_socks; n++) {
sock = socks[n];
nc = channel_new(ssh, "x11-listener",
Expand Down
8 changes: 6 additions & 2 deletions fixalloc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# | 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})"
Expand All @@ -52,6 +52,10 @@
# | match |
# "zrealloc(zrestrict(#{$1}, typeof(#{$4}), #{$2}), typeof(#{$4}), #{$3})"
#}
contents.gsub!(/xzrealloc/) { | match | "zrealloc" }
#contents.gsub!(/xzrealloc/) { | match | "zrealloc" }
#contents.gsub!(/calloc\(([^\n]+), sizeof\(([a-zA-Z0-9_ *]+)\)\)/) {
# | match |
# "zalloc(#{$2}, #{$1})"
#}
IO::write(filename, contents)
}
2 changes: 1 addition & 1 deletion gss-genr.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ssh_gssapi_set_oid_data(Gssctxt *ctx, void *data, size_t len)
free(ctx->oid->elements);
free(ctx->oid);
}
ctx->oid = xcalloc(1, sizeof(gss_OID_desc));
ctx->oid = zalloc(gss_OID_desc, 1);
ctx->oid->length = len;
ctx->oid->elements = xmalloc(len);
memcpy(ctx->oid->elements, data, len);
Expand Down
2 changes: 1 addition & 1 deletion kex.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ kex_buf2prop(struct sshbuf *raw, int *first_kex_follows, char ***propp)
int r;

*propp = NULL;
if ((proposal = calloc(PROPOSAL_MAX, sizeof(char *))) == NULL)
if ((proposal = zalloc(char *, PROPOSAL_MAX)) == NULL)
return SSH_ERR_ALLOC_FAIL;
if ((b = sshbuf_fromb(raw)) == NULL) {
r = SSH_ERR_ALLOC_FAIL;
Expand Down
6 changes: 3 additions & 3 deletions moduli.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,16 @@ gen_candidates(FILE *out, u_int32_t memory, u_int32_t power, BIGNUM *start)
largewords = (largememory << SHIFT_MEGAWORD);
}

TinySieve = xcalloc(tinywords, sizeof(u_int32_t));
TinySieve = zalloc(u_int32_t, tinywords);
tinybits = tinywords << SHIFT_WORD;

SmallSieve = xcalloc(smallwords, sizeof(u_int32_t));
SmallSieve = zalloc(u_int32_t, smallwords);
smallbits = smallwords << SHIFT_WORD;

/*
* dynamically determine available memory
*/
while ((LargeSieve = calloc(largewords, sizeof(u_int32_t))) == NULL)
while ((LargeSieve = zalloc(u_int32_t, largewords)) == NULL)
largewords -= (1L << (SHIFT_MEGAWORD - 2)); /* 1/4 MB chunks */

largebits = largewords << SHIFT_WORD;
Expand Down
2 changes: 1 addition & 1 deletion monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ mm_answer_pam_respond(struct ssh *ssh, int sock, struct sshbuf *m)
num, (unsigned)PAM_MAX_NUM_MSG);
}
if (num > 0) {
resp = xcalloc(num, sizeof(char *));
resp = zalloc(char *, num);
for (i = 0; i < num; ++i) {
if ((r = sshbuf_get_cstring(m, &(resp[i]), NULL)) != 0)
fatal("%s: buffer error: %s",
Expand Down
10 changes: 5 additions & 5 deletions monitor_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ mm_sshkey_verify(const struct sshkey *key, const u_char *sig, size_t siglen,
(r = sshbuf_get_u8(m, &flags)) != 0)
fatal_fr(r, "parse sig_details");
if (sig_detailsp != NULL) {
*sig_detailsp = xcalloc(1, sizeof(**sig_detailsp));
*sig_detailsp = zalloc(typeof(**sig_detailsp), 1);
(*sig_detailsp)->sk_counter = counter;
(*sig_detailsp)->sk_flags = flags;
}
Expand Down Expand Up @@ -737,8 +737,8 @@ mm_sshpam_query(void *ctx, char **name, char **info,
if (*num > PAM_MAX_NUM_MSG)
fatal("%s: received %u PAM messages, expected <= %u",
__func__, *num, PAM_MAX_NUM_MSG);
*prompts = xcalloc((*num + 1), sizeof(char *));
*echo_on = xcalloc((*num + 1), sizeof(u_int));
*prompts = zalloc(char *, (*num + 1));
*echo_on = zalloc(u_int, (*num + 1));
for (i = 0; i < *num; ++i) {
if ((r = sshbuf_get_cstring(m, &((*prompts)[i]), NULL)) != 0 ||
(r = sshbuf_get_u32(m, &((*echo_on)[i]))) != 0)
Expand Down Expand Up @@ -812,8 +812,8 @@ mm_chall_setup(char **name, char **infotxt, u_int *numprompts,
*name = xstrdup("");
*infotxt = xstrdup("");
*numprompts = 1;
*prompts = xcalloc(*numprompts, sizeof(char *));
*echo_on = xcalloc(*numprompts, sizeof(u_int));
*prompts = zalloc(char *, *numprompts);
*echo_on = zalloc(u_int, *numprompts);
(*echo_on)[0] = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions openbsd-compat/arc4random.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ _rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
return (-1);
}
#else
if ((*rsp = calloc(1, sizeof(**rsp))) == NULL)
if ((*rsp = zalloc(typeof(**rsp), 1)) == NULL)
return (-1);
if ((*rsxp = calloc(1, sizeof(**rsxp))) == NULL) {
if ((*rsxp = zalloc(typeof(**rsxp), 1)) == NULL) {
free(*rsp);
*rsp = NULL;
return (-1);
Expand Down
2 changes: 1 addition & 1 deletion openbsd-compat/bsd-cygwin_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fetch_windows_environment(void)
char **e, **p;
unsigned int i, idx = 0;

p = xcalloc(WENV_SIZ + 1, sizeof(char *));
p = zalloc(char *, WENV_SIZ + 1);
for (e = environ; *e != NULL; ++e) {
for (i = 0; i < WENV_SIZ; ++i) {
if (!strncmp(*e, wenv_arr[i].name, wenv_arr[i].namelen))
Expand Down
2 changes: 1 addition & 1 deletion openbsd-compat/getrrsetbyname-ldns.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
}

/* initialize rrset */
rrset = calloc(1, sizeof(struct rrsetinfo));
rrset = zalloc(struct rrsetinfo, 1);
if (rrset == NULL) {
result = ERRSET_NOMEMORY;
goto fail;
Expand Down
8 changes: 4 additions & 4 deletions openbsd-compat/getrrsetbyname.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
}

/* initialize rrset */
rrset = calloc(1, sizeof(struct rrsetinfo));
rrset = zalloc(struct rrsetinfo, 1);
if (rrset == NULL) {
result = ERRSET_NOMEMORY;
goto fail;
Expand Down Expand Up @@ -305,7 +305,7 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,

/* allocate memory for signatures */
if (rrset->rri_nsigs > 0) {
rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo));
rrset->rri_sigs = zalloc(struct rdatainfo, rrset->rri_nsigs);
if (rrset->rri_sigs == NULL) {
result = ERRSET_NOMEMORY;
goto fail;
Expand Down Expand Up @@ -472,7 +472,7 @@ parse_dns_qsection(const u_char *answer, int size, const u_char **cp, int count)
return (NULL);
}
/* allocate and initialize struct */
curr = calloc(1, sizeof(struct dns_query));
curr = zalloc(struct dns_query, 1);
if (curr == NULL)
goto fail;
if (head == NULL)
Expand Down Expand Up @@ -532,7 +532,7 @@ parse_dns_rrsection(const u_char *answer, int size, const u_char **cp,
}

/* allocate and initialize struct */
curr = calloc(1, sizeof(struct dns_rr));
curr = zalloc(struct dns_rr, 1);
if (curr == NULL)
goto fail;
if (head == NULL)
Expand Down
4 changes: 2 additions & 2 deletions regress/misc/fuzz-harness/agent_fuzz_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ add_key(const char *privkey, const char *certpath)
int r;
struct sshkey *cert;

id = xcalloc(1, sizeof(Identity));
id = zalloc(Identity, 1);
TAILQ_INSERT_TAIL(&idtab->idlist, id, next);
idtab->nentries++;
id->key = privkey_or_die(privkey);
Expand All @@ -71,7 +71,7 @@ add_key(const char *privkey, const char *certpath)
id->sk_provider = xstrdup("internal");

/* Now the cert too */
id = xcalloc(1, sizeof(Identity));
id = zalloc(Identity, 1);
TAILQ_INSERT_TAIL(&idtab->idlist, id, next);
idtab->nentries++;
id->key = privkey_or_die(privkey);
Expand Down
2 changes: 1 addition & 1 deletion session.c
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ do_setup_env(struct ssh *ssh, Session *s, const char *shell)

/* Initialize the environment. */
envsize = 100;
env = xcalloc(envsize, sizeof(char *));
env = zalloc(char *, envsize);
env[0] = NULL;

#ifdef HAVE_CYGWIN
Expand Down
6 changes: 3 additions & 3 deletions sftp-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ sftp_lsreaddir(struct sftp_conn *conn, const char *path, int print_flag,

if (dir) {
ents = 0;
*dir = xcalloc(1, sizeof(**dir));
*dir = zalloc(typeof(**dir), 1);
(*dir)[0] = NULL;
}

Expand Down Expand Up @@ -811,7 +811,7 @@ sftp_lsreaddir(struct sftp_conn *conn, const char *path, int print_flag,
"during readdir of \"%s\"", filename, path);
} else if (dir) {
*dir = xreallocarray(*dir, ents + 2, sizeof(**dir));
(*dir)[ents] = xcalloc(1, sizeof(***dir));
(*dir)[ents] = zalloc(typeof(***dir), 1);
(*dir)[ents]->filename = xstrdup(filename);
(*dir)[ents]->longname = xstrdup(longname);
memcpy(&(*dir)[ents]->a, &a, sizeof(a));
Expand All @@ -835,7 +835,7 @@ sftp_lsreaddir(struct sftp_conn *conn, const char *path, int print_flag,
} else if (interrupted && dir != NULL && *dir != NULL) {
/* Don't return partial matches on interrupt */
sftp_free_dirents(*dir);
*dir = xcalloc(1, sizeof(**dir));
*dir = zalloc(typeof(**dir), 1);
**dir = NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion sftp-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ process_readdir(u_int32_t id)
Stat *stats;
int nstats = 10, count = 0, i;

stats = xcalloc(nstats, sizeof(Stat));
stats = zalloc(Stat, nstats);
while ((dp = readdir(dirp)) != NULL) {
if (count >= nstats) {
nstats *= 2;
Expand Down
2 changes: 1 addition & 1 deletion sftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ complete_cmd_parse(EditLine *el, char *cmd, int lastarg, char quote,
char *tmp, **list, argterm[3];
const LineInfo *lf;

list = xcalloc((sizeof(cmds) / sizeof(*cmds)) + 1, sizeof(char *));
list = zalloc(char *, (sizeof(cmds) / sizeof(*cmds)) + 1);

/* No command specified: display all available commands */
if (cmd == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion ssh-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ stringlist_append(char ***listp, const char *s)
size_t i = 0;

if (*listp == NULL)
*listp = xcalloc(2, sizeof(**listp));
*listp = zalloc(typeof(**listp), 2);
else {
for (i = 0; (*listp)[i] != NULL; i++)
; /* count */
Expand Down
4 changes: 2 additions & 2 deletions ssh-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ process_add_identity(SocketEntry *e)
if (lifetime && !death)
death = monotime() + lifetime;
if ((id = lookup_identity(k)) == NULL) {
id = xcalloc(1, sizeof(Identity));
id = zalloc(Identity, 1);
TAILQ_INSERT_TAIL(&idtab->idlist, id, next);
/* Increment the number of identities. */
idtab->nentries++;
Expand Down Expand Up @@ -1531,7 +1531,7 @@ add_p11_identity(struct sshkey *key, char *comment, const char *provider,
free(comment);
return;
}
id = xcalloc(1, sizeof(Identity));
id = zalloc(Identity, 1);
id->key = key;
id->comment = comment;
id->provider = xstrdup(provider);
Expand Down
4 changes: 2 additions & 2 deletions ssh-keyscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,8 @@ main(int argc, char **argv)
fatal("%s: not enough file descriptors", __progname);
if (maxfd > fdlim_get(0))
fdlim_set(maxfd);
fdcon = xcalloc(maxfd, sizeof(con));
read_wait = xcalloc(maxfd, sizeof(struct pollfd));
fdcon = zalloc(con, maxfd);
read_wait = zalloc(struct pollfd, maxfd);
for (j = 0; j < maxfd; j++)
read_wait[j].fd = -1;

Expand Down
4 changes: 2 additions & 2 deletions ssh-pkcs11-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,9 @@ pkcs11_add_provider(char *name, char *pin, struct sshkey ***keysp,
if (type == SSH2_AGENT_IDENTITIES_ANSWER) {
if ((r = sshbuf_get_u32(msg, &nkeys)) != 0)
fatal_fr(r, "parse nkeys");
*keysp = xcalloc(nkeys, sizeof(struct sshkey *));
*keysp = zalloc(struct sshkey *, nkeys);
if (labelsp)
*labelsp = xcalloc(nkeys, sizeof(char *));
*labelsp = zalloc(char *, nkeys);
for (i = 0; i < nkeys; i++) {
/* XXX clean up properly instead of fatal() */
if ((r = sshbuf_get_string(msg, &blob, &blen)) != 0 ||
Expand Down
4 changes: 2 additions & 2 deletions ssh-pkcs11.c
Original file line number Diff line number Diff line change
Expand Up @@ -1585,14 +1585,14 @@ pkcs11_register_provider(char *provider_id, char *pin,
ret = -SSH_PKCS11_ERR_NO_SLOTS;
goto fail;
}
p->slotlist = xcalloc(p->nslots, sizeof(CK_SLOT_ID));
p->slotlist = zalloc(CK_SLOT_ID, p->nslots);
if ((rv = f->C_GetSlotList(CK_TRUE, p->slotlist, &p->nslots))
!= CKR_OK) {
error("C_GetSlotList for provider %s failed: %lu",
provider_id, rv);
goto fail;
}
p->slotinfo = xcalloc(p->nslots, sizeof(struct pkcs11_slotinfo));
p->slotinfo = zalloc(struct pkcs11_slotinfo, p->nslots);
p->valid = 1;
nkeys = 0;
for (i = 0; i < p->nslots; i++) {
Expand Down
2 changes: 1 addition & 1 deletion ssh-sk.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ sshsk_add_option(struct sk_option ***optsp, size_t *noptsp,
}
*optsp = opts;
*noptsp = nopts + 1;
if ((opts[nopts] = calloc(1, sizeof(**opts))) == NULL) {
if ((opts[nopts] = zalloc(typeof(**opts), 1)) == NULL) {
error_f("alloc failed");
return SSH_ERR_ALLOC_FAIL;
}
Expand Down
8 changes: 4 additions & 4 deletions sshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,9 +1127,9 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
sigset_t nsigset, osigset;

/* pipes connected to unauthenticated child sshd processes */
startup_pipes = xcalloc(options.max_startups, sizeof(int));
startup_flags = xcalloc(options.max_startups, sizeof(int));
startup_pollfd = xcalloc(options.max_startups, sizeof(int));
startup_pipes = zalloc(int, options.max_startups);
startup_flags = zalloc(int, options.max_startups);
startup_pollfd = zalloc(int, options.max_startups);
for (i = 0; i < options.max_startups; i++)
startup_pipes[i] = -1;

Expand Down Expand Up @@ -2017,7 +2017,7 @@ main(int ac, char **av)
if (rexec_flag) {
if (rexec_argc < 0)
fatal("rexec_argc %d < 0", rexec_argc);
rexec_argv = xcalloc(rexec_argc + 2, sizeof(char *));
rexec_argv = zalloc(char *, rexec_argc + 2);
for (i = 0; i < (u_int)rexec_argc; i++) {
debug("rexec_argv[%d]='%s'", i, saved_argv[i]);
rexec_argv[i] = saved_argv[i];
Expand Down
4 changes: 2 additions & 2 deletions xmss_wots.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int wots_sign(unsigned char *sig, const unsigned char *msg, const unsigned char
//int basew[params->len];
int csum = 0;
uint32_t i = 0;
int *basew = calloc(params->len, sizeof(int));
int *basew = zalloc(int, params->len);
if (basew == NULL)
return -1;

Expand Down Expand Up @@ -159,7 +159,7 @@ int wots_pkFromSig(unsigned char *pk, const unsigned char *sig, const unsigned c
{
int csum = 0;
uint32_t i = 0;
int *basew = calloc(params->len, sizeof(int));
int *basew = zalloc(int, params->len);
if (basew == NULL)
return -1;

Expand Down

0 comments on commit 010801d

Please sign in to comment.