diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 1998-08-16 02:42:12 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 1998-08-16 02:42:12 +0000 |
commit | 364a0613877e4712a7614d08e62ec043adfbf94b (patch) | |
tree | 6d958783b2dd21a5d023a0db66ec592659ae63ad /kerberosIV | |
parent | 7f6450fdf2329ea9c097d81109b3f08742bf8a4d (diff) |
realloc fixes
Diffstat (limited to 'kerberosIV')
-rw-r--r-- | kerberosIV/kadm/kadm_cli_wrap.c | 41 | ||||
-rw-r--r-- | kerberosIV/kadm/kadm_stream.c | 31 | ||||
-rw-r--r-- | kerberosIV/kadmin/sl.c | 11 | ||||
-rw-r--r-- | kerberosIV/kadmind/admin_server.c | 12 | ||||
-rw-r--r-- | kerberosIV/kauth/rkinit.c | 15 | ||||
-rw-r--r-- | kerberosIV/kerberos/kerberos.c | 6 |
6 files changed, 91 insertions, 25 deletions
diff --git a/kerberosIV/kadm/kadm_cli_wrap.c b/kerberosIV/kadm/kadm_cli_wrap.c index d76f50a620e..3246442308f 100644 --- a/kerberosIV/kadm/kadm_cli_wrap.c +++ b/kerberosIV/kadm/kadm_cli_wrap.c @@ -1,5 +1,17 @@ -/* $OpenBSD: kadm_cli_wrap.c,v 1.5 1997/12/15 17:56:17 art Exp $ */ -/* $KTH: kadm_cli_wrap.c,v 1.22 1997/08/17 07:30:04 assar Exp $ */ +/* $OpenBSD: kadm_cli_wrap.c,v 1.6 1998/08/16 02:42:05 art Exp $ */ +/* $KTH: kadm_cli_wrap.c,v 1.22 1997/08/17 07:30:04 assar Exp $ */ + +/* + * This source code is no longer held under any constraint of USA + * `cryptographic laws' since it was exported legally. The cryptographic + * functions were removed from the code and a "Bones" distribution was + * made. A Commodity Jurisdiction Request #012-94 was filed with the + * USA State Department, who handed it to the Commerce department. The + * code was determined to fall under General License GTDA under ECCN 5D96G, + * and hence exportable. The cryptographic interfaces were re-added by Eric + * Young, and then KTH proceeded to maintain the code in the free world. + * + */ /* Copyright (C) 1989 by the Massachusetts Institute of Technology @@ -239,6 +251,7 @@ kadm_cli_send(u_char *st_dat, int st_siz, u_char **ret_dat, int *ret_siz) * data */ KTEXT_ST authent; /* the authenticator we will build */ u_char *act_st; /* the pointer to the complete packet */ + u_char *temp; u_char *priv_pak; /* private version of the packet */ int priv_len; /* length of private packet */ u_int32_t cksum; /* checksum of the packet */ @@ -293,14 +306,17 @@ kadm_cli_send(u_char *st_dat, int st_siz, u_char **ret_dat, int *ret_siz) RET_N_FREE(retdat + krb_err_base); } - act_st = (u_char *) realloc(act_st, + temp = (u_char *) realloc(act_st, act_len + authent.length + priv_len); - if (act_st == NULL) { + if (temp == NULL) { clear_secrets(); free(priv_pak); + free(act_st); priv_pak = NULL; return KADM_NOMEM; } + act_st = temp; + memcpy((char *)act_st + act_len, authent.dat, authent.length); memcpy((char *)act_st + act_len + authent.length, priv_pak, priv_len); free(priv_pak); @@ -369,6 +385,7 @@ int kadm_change_pw_plain(unsigned char *newkey, char *password, char **pw_msg) { int stsize, retc; /* stream size and return code */ u_char *send_st; /* send stream */ + u_char *temp; u_char *ret_st; int ret_sz; int status; @@ -387,9 +404,12 @@ int kadm_change_pw_plain(unsigned char *newkey, char *password, char **pw_msg) /* change key to stream */ - send_st = realloc(send_st, stsize + 8); - if (send_st == NULL) + temp = realloc(send_st, stsize + 8); + if (temp == NULL) { + free(send_st); return KADM_NOMEM; + } + send_st = temp; memcpy(send_st + stsize + 4, newkey, 4); /* yes, this is backwards */ memcpy(send_st + stsize, newkey + 4, 4); @@ -502,6 +522,7 @@ kadm_mod(Kadm_vals *vals1, Kadm_vals *vals2) u_char *st, *st2; /* st will hold the stream of values */ int st_len, nlen; /* st2 the final stream with opcode */ u_char *ret_st; + u_char *temp; int ret_sz; /* nlen is the length of second vals */ @@ -521,7 +542,13 @@ kadm_mod(Kadm_vals *vals1, Kadm_vals *vals2) st = NULL; nlen = vals_to_stream(vals2, &st); - st2 = (u_char *) realloc((char *) st2, (unsigned)(st_len + nlen)); + temp = (u_char *) realloc((char *) st2, (unsigned)(st_len + nlen)); + if (temp == NULL) { + free(st2); + return KADM_NOMEM; + } + st2 = temp; + memcpy((char *) st2 + st_len, st, nlen); /* append st on */ retc = kadm_cli_send(st2, st_len + nlen, &ret_st, &ret_sz); diff --git a/kerberosIV/kadm/kadm_stream.c b/kerberosIV/kadm/kadm_stream.c index 9f10aa45e1b..791a553a0b4 100644 --- a/kerberosIV/kadm/kadm_stream.c +++ b/kerberosIV/kadm/kadm_stream.c @@ -1,5 +1,17 @@ -/* $OpenBSD: kadm_stream.c,v 1.4 1997/12/12 10:02:47 art Exp $ */ -/* $KTH: kadm_stream.c,v 1.11 1997/05/02 10:28:05 joda Exp $ */ +/* $OpenBSD: kadm_stream.c,v 1.5 1998/08/16 02:42:06 art Exp $ */ +/* $KTH: kadm_stream.c,v 1.11 1997/05/02 10:28:05 joda Exp $ */ + +/* + * This source code is no longer held under any constraint of USA + * `cryptographic laws' since it was exported legally. The cryptographic + * functions were removed from the code and a "Bones" distribution was + * made. A Commodity Jurisdiction Request #012-94 was filed with the + * USA State Department, who handed it to the Commerce department. The + * code was determined to fall under General License GTDA under ECCN 5D96G, + * and hence exportable. The cryptographic interfaces were re-added by Eric + * Young, and then KTH proceeded to maintain the code in the free world. + * + */ /* Copyright (C) 1989 by the Massachusetts Institute of Technology @@ -71,9 +83,15 @@ vts_string(char *dat, u_char **st, int loc) /* base pointer to the stream */ /* offset into the stream for current data */ { - *st = (u_char *) realloc (*st, (unsigned) (loc + strlen(dat) + 1)); - if (*st == NULL) + u_char *temp; + + temp = (u_char *) realloc (*st, (unsigned) (loc + strlen(dat) + 1)); + if (temp == NULL) { + free(*st); return -1; + } + *st = temp; + memcpy(*st + loc, dat, strlen(dat)+1); return strlen(dat)+1; } @@ -86,8 +104,9 @@ vts_short(u_int16_t dat, u_char **st, int loc) /* offset into the stream for current data */ { unsigned char *p; + p = realloc(*st, loc + 2); - if(p == NULL){ + if (p == NULL) { abort(); } p[loc] = (dat >> 8) & 0xff; @@ -103,7 +122,7 @@ vts_char(u_char dat, u_char **st, int loc) /* offset into the stream for current data */ { unsigned char *p = realloc(*st, loc + 1); - if(p == NULL){ + if (p == NULL) { abort(); } p[loc] = dat; diff --git a/kerberosIV/kadmin/sl.c b/kerberosIV/kadmin/sl.c index 6b75e98ab50..5ec5500406a 100644 --- a/kerberosIV/kadmin/sl.c +++ b/kerberosIV/kadmin/sl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sl.c,v 1.2 1998/02/18 11:53:46 art Exp $ */ +/* $OpenBSD: sl.c,v 1.3 1998/08/16 02:42:07 art Exp $ */ /* $KTH: sl.c,v 1.15 1997/10/19 23:12:40 assar Exp $ */ /* @@ -168,14 +168,19 @@ sl_loop (SL_cmd *cmds, char *prompt) p; p = strtok_r (NULL, " \t", &foo)) { if(count == max_count) { + char **temp; + max_count *= 2; - ptr = realloc (ptr, max_count * sizeof(*ptr)); - if (ptr == NULL) { + temp = realloc (ptr, max_count * sizeof(*ptr)); + if (temp == NULL) { printf ("sl_loop: failed to allocate %u " "bytes of memory\n", (unsigned) max_count * sizeof(*ptr)); + + free(ptr); return -1; } + ptr = temp; } ptr[count++] = p; } diff --git a/kerberosIV/kadmind/admin_server.c b/kerberosIV/kadmind/admin_server.c index 9532edbb26b..5467b871eed 100644 --- a/kerberosIV/kadmind/admin_server.c +++ b/kerberosIV/kadmind/admin_server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: admin_server.c,v 1.3 1997/12/15 17:56:21 art Exp $ */ +/* $OpenBSD: admin_server.c,v 1.4 1998/08/16 02:42:09 art Exp $ */ /* $KTH: admin_server.c,v 1.42 1997/12/04 19:31:39 assar Exp $ */ /* @@ -250,6 +250,7 @@ kadm_listen(void) struct sockaddr_in peer; int addrlen; int pid; + int *temp; signal(SIGINT, doexit); signal(SIGTERM, doexit); @@ -299,6 +300,14 @@ kadm_listen(void) continue; } #ifndef DEBUG + /* grow the pidarray before forking, so we can catch the errors */ + temp = realloc(pidarray, ++pidarraysize); + if (temp == NULL) { + krb_log("realloc: %s", error_message(errno)); + close(peer_fd); + continue; + } + pidarray = temp; /* if you want a sep daemon for each server */ if ((pid = fork())) { /* parent */ @@ -309,7 +318,6 @@ kadm_listen(void) } /* fork succeded: keep tabs on child */ close(peer_fd); - pidarray = realloc(pidarray, ++pidarraysize); pidarray[pidarraysize-1] = pid; } else { /* child */ diff --git a/kerberosIV/kauth/rkinit.c b/kerberosIV/kauth/rkinit.c index 615b6592583..713c9df9547 100644 --- a/kerberosIV/kauth/rkinit.c +++ b/kerberosIV/kauth/rkinit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rkinit.c,v 1.1 1997/12/18 22:28:05 art Exp $ */ +/* $OpenBSD: rkinit.c,v 1.2 1998/08/16 02:42:10 art Exp $ */ /* $KTH: rkinit.c,v 1.19 1997/04/01 08:17:33 joda Exp $ */ /* @@ -47,6 +47,7 @@ getalladdrs (char *hostname, unsigned *count) struct hostent *hostent; struct in_addr **h; struct in_addr *addr; + struct in_addr *temp; unsigned naddr; unsigned maxaddr; @@ -74,19 +75,23 @@ getalladdrs (char *hostname, unsigned *count) h++) { if (naddr >= maxaddr) { maxaddr *= 2; - addr = realloc (addr, sizeof(*addr) * maxaddr); - if (addr == NULL) { + temp = realloc (addr, sizeof(*addr) * maxaddr); + if (temp == NULL) { warnx ("out of memory"); + free(addr); return NULL; } + addr = temp; } addr[naddr++] = **h; } - addr = realloc (addr, sizeof(*addr) * naddr); - if (addr == NULL) { + temp = realloc (addr, sizeof(*addr) * naddr); + if (temp == NULL) { warnx ("out of memory"); + free(addr); return NULL; } + addr = temp; *count = naddr; return addr; } diff --git a/kerberosIV/kerberos/kerberos.c b/kerberosIV/kerberos/kerberos.c index 0138f9bad86..11d85f7407e 100644 --- a/kerberosIV/kerberos/kerberos.c +++ b/kerberosIV/kerberos/kerberos.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kerberos.c,v 1.13 1998/07/13 19:57:19 art Exp $ */ +/* $OpenBSD: kerberos.c,v 1.14 1998/08/16 02:42:11 art Exp $ */ /* $KTH: kerberos.c,v 1.70 1997/09/26 18:06:38 joda Exp $ */ /* @@ -575,8 +575,10 @@ add_port(struct port_spec **ports, int *num_ports, int port, int type) { struct port_spec *tmp; tmp = realloc(*ports, (*num_ports + 1) * sizeof(*tmp)); - if(tmp == NULL) + if(tmp == NULL) { + free(*ports); return ENOMEM; + } *ports = tmp; tmp[*num_ports].port = port; tmp[*num_ports].type = type; |