diff options
-rw-r--r-- | sbin/isakmpd/policy.c | 118 | ||||
-rw-r--r-- | sbin/isakmpd/x509.c | 40 |
2 files changed, 80 insertions, 78 deletions
diff --git a/sbin/isakmpd/policy.c b/sbin/isakmpd/policy.c index 10eae078e02..a1c1b92dd59 100644 --- a/sbin/isakmpd/policy.c +++ b/sbin/isakmpd/policy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: policy.c,v 1.47 2002/01/03 09:24:02 ho Exp $ */ +/* $OpenBSD: policy.c,v 1.48 2002/01/23 17:25:38 ho Exp $ */ /* $EOM: policy.c,v 1.49 2000/10/24 13:33:39 niklas Exp $ */ /* @@ -147,7 +147,7 @@ my_inet_ntop4 (const in_addr_t *src, char *dst, size_t size, int normalize) errno = ENOSPC; return 0; } - strcpy (dst, tmp); + strlcpy (dst, tmp, size); return dst; } @@ -164,7 +164,7 @@ my_inet_ntop6 (const unsigned char *src, char *dst, size_t size) errno = ENOSPC; return 0; } - strcpy (dst, tmp); + strlcpy (dst, tmp, size); return dst; } @@ -186,29 +186,31 @@ policy_callback (char *name) static char mytimeofday[15]; /* We use all these as a cache. */ +#define PMAX 32 static char *esp_present, *ah_present, *comp_present; static char *ah_hash_alg, *ah_auth_alg, *esp_auth_alg, *esp_enc_alg; - static char *comp_alg, ah_life_kbytes[32], ah_life_seconds[32]; - static char esp_life_kbytes[32], esp_life_seconds[32], comp_life_kbytes[32]; - static char comp_life_seconds[32], *ah_encapsulation, *esp_encapsulation; - static char *comp_encapsulation, ah_key_length[32], esp_key_length[32]; - static char ah_key_rounds[32], esp_key_rounds[32], comp_dict_size[32]; - static char comp_private_alg[32], *remote_filter_type, *local_filter_type; + static char *comp_alg, ah_life_kbytes[PMAX], ah_life_seconds[PMAX]; + static char esp_life_kbytes[PMAX], esp_life_seconds[PMAX]; + static char comp_life_kbytes[PMAX]; + static char comp_life_seconds[PMAX], *ah_encapsulation, *esp_encapsulation; + static char *comp_encapsulation, ah_key_length[PMAX], esp_key_length[PMAX]; + static char ah_key_rounds[PMAX], esp_key_rounds[PMAX], comp_dict_size[PMAX]; + static char comp_private_alg[PMAX], *remote_filter_type, *local_filter_type; static char remote_filter_addr_upper[NI_MAXHOST]; static char remote_filter_addr_lower[NI_MAXHOST]; static char local_filter_addr_upper[NI_MAXHOST]; static char local_filter_addr_lower[NI_MAXHOST]; - static char ah_group_desc[32], esp_group_desc[32], comp_group_desc[32]; + static char ah_group_desc[PMAX], esp_group_desc[PMAX], comp_group_desc[PMAX]; static char remote_ike_address[NI_MAXHOST]; static char local_ike_address[NI_MAXHOST]; static char *remote_id_type, remote_id_addr_upper[NI_MAXHOST], *phase_1; static char remote_id_addr_lower[NI_MAXHOST]; - static char *remote_id_proto, remote_id_port[32]; - static char remote_filter_port[32], local_filter_port[32]; + static char *remote_id_proto, remote_id_port[PMAX]; + static char remote_filter_port[PMAX], local_filter_port[PMAX]; static char *remote_filter_proto, *local_filter_proto, *pfs, *initiator; static char remote_filter_proto_num[3], local_filter_proto_num[3]; static char remote_id_proto_num[3]; - static char phase1_group[32]; + static char phase1_group[PMAX]; /* Allocated. */ static char *remote_filter = 0, *local_filter = 0, *remote_id = 0; @@ -287,7 +289,7 @@ policy_callback (char *name) pfs = "yes"; is = policy_isakmp_sa->data; - sprintf (phase1_group, "%u", is->group_desc); + snprintf (phase1_group, PMAX, "%u", is->group_desc); for (proto = TAILQ_FIRST (&policy_sa->protos); proto; proto = TAILQ_NEXT (proto, link)) @@ -431,20 +433,20 @@ policy_callback (char *name) if (lifetype == IPSEC_DURATION_SECONDS) { if (len == 2) - sprintf (ah_life_seconds, "%u", - decode_16 (value)); + snprintf (ah_life_seconds, PMAX, "%u", + decode_16 (value)); else - sprintf (ah_life_seconds, "%u", - decode_32 (value)); + snprintf (ah_life_seconds, PMAX, "%u", + decode_32 (value)); } else { if (len == 2) - sprintf (ah_life_kbytes, "%u", - decode_16 (value)); + snprintf (ah_life_kbytes, PMAX, "%u", + decode_16 (value)); else - sprintf (ah_life_kbytes, "%u", - decode_32 (value)); + snprintf (ah_life_kbytes, PMAX, "%u", + decode_32 (value)); } break; @@ -453,20 +455,20 @@ policy_callback (char *name) if (lifetype == IPSEC_DURATION_SECONDS) { if (len == 2) - sprintf (esp_life_seconds, "%u", - decode_16 (value)); + snprintf (esp_life_seconds, PMAX, "%u", + decode_16 (value)); else - sprintf (esp_life_seconds, "%u", - decode_32 (value)); + snprintf (esp_life_seconds, PMAX, "%u", + decode_32 (value)); } else { if (len == 2) - sprintf (esp_life_kbytes, "%u", - decode_16 (value)); + snprintf (esp_life_kbytes, PMAX, "%u", + decode_16 (value)); else - sprintf (esp_life_kbytes, "%u", - decode_32 (value)); + snprintf (esp_life_kbytes, PMAX, "%u", + decode_32 (value)); } break; @@ -475,20 +477,20 @@ policy_callback (char *name) if (lifetype == IPSEC_DURATION_SECONDS) { if (len == 2) - sprintf (comp_life_seconds, "%u", - decode_16 (value)); + snprintf (comp_life_seconds, PMAX, "%u", + decode_16 (value)); else - sprintf (comp_life_seconds, "%u", - decode_32 (value)); + snprintf (comp_life_seconds, PMAX, "%u", + decode_32 (value)); } else { if (len == 2) - sprintf (comp_life_kbytes, "%u", - decode_16 (value)); + snprintf (comp_life_kbytes, PMAX, "%u", + decode_16 (value)); else - sprintf (comp_life_kbytes, "%u", - decode_32 (value)); + snprintf (comp_life_kbytes, PMAX, "%u", + decode_32 (value)); } break; @@ -499,16 +501,16 @@ policy_callback (char *name) switch (proto->proto) { case IPSEC_PROTO_IPSEC_AH: - sprintf (ah_group_desc, "%u", decode_16 (value)); + snprintf (ah_group_desc, PMAX, "%u", decode_16 (value)); break; case IPSEC_PROTO_IPSEC_ESP: - sprintf (esp_group_desc, "%u", + snprintf (esp_group_desc, PMAX, "%u", decode_16 (value)); break; case IPSEC_PROTO_IPCOMP: - sprintf (comp_group_desc, "%u", + snprintf (comp_group_desc, PMAX, "%u", decode_16 (value)); break; } @@ -606,11 +608,11 @@ policy_callback (char *name) switch (proto->proto) { case IPSEC_PROTO_IPSEC_AH: - sprintf (ah_key_length, "%u", decode_16 (value)); + snprintf (ah_key_length, PMAX, "%u", decode_16 (value)); break; case IPSEC_PROTO_IPSEC_ESP: - sprintf (esp_key_length, "%u", + snprintf (esp_key_length, PMAX, "%u", decode_16 (value)); break; } @@ -620,22 +622,22 @@ policy_callback (char *name) switch (proto->proto) { case IPSEC_PROTO_IPSEC_AH: - sprintf (ah_key_rounds, "%u", decode_16 (value)); + snprintf (ah_key_rounds, PMAX, "%u", decode_16 (value)); break; case IPSEC_PROTO_IPSEC_ESP: - sprintf (esp_key_rounds, "%u", + snprintf (esp_key_rounds, PMAX, "%u", decode_16 (value)); break; } break; case IPSEC_ATTR_COMPRESS_DICTIONARY_SIZE: - sprintf (comp_dict_size, "%u", decode_16 (value)); + snprintf (comp_dict_size, PMAX, "%u", decode_16 (value)); break; case IPSEC_ATTR_COMPRESS_PRIVATE_ALGORITHM: - sprintf (comp_private_alg, "%u", decode_16 (value)); + snprintf (comp_private_alg, PMAX, "%u", decode_16 (value)); break; } } @@ -647,8 +649,7 @@ policy_callback (char *name) log_error ("policy_callback: sockaddr2text failed"); goto bad; } - strncpy (local_ike_address, addr, sizeof local_ike_address); - local_ike_address[sizeof local_ike_address - 1] = '\0'; + strlcpy (local_ike_address, addr, sizeof local_ike_address); free (addr); policy_sa->transport->vtbl->get_dst (policy_sa->transport, &sin); @@ -657,8 +658,7 @@ policy_callback (char *name) log_error ("policy_callback: sockaddr2text failed"); goto bad; } - strncpy (remote_ike_address, addr, sizeof remote_ike_address); - remote_ike_address[sizeof remote_ike_address - 1] = '\0'; + strlcpy (remote_ike_address, addr, sizeof remote_ike_address); free (addr); switch (policy_isakmp_sa->exch_type) @@ -944,7 +944,7 @@ policy_callback (char *name) #endif default: - sprintf (remote_id_proto_num, "%2d", id[1]); + snprintf (remote_id_proto_num, 3, "%2d", id[1]); remote_id_proto = remote_id_proto_num; break; } @@ -1229,7 +1229,7 @@ policy_callback (char *name) #endif default: - sprintf (remote_filter_proto_num, "%2d", + snprintf (remote_filter_proto_num, 3, "%2d", idremote[ISAKMP_GEN_SZ + 1]); remote_filter_proto = remote_filter_proto_num; break; @@ -1532,7 +1532,7 @@ policy_callback (char *name) #endif default: - sprintf (local_filter_proto_num, "%2d", + snprintf (local_filter_proto_num, 3, "%2d", idlocal[ISAKMP_GEN_SZ + 1]); local_filter_proto = local_filter_proto_num; break; @@ -2067,7 +2067,8 @@ keynote_cert_obtain (u_int8_t *id, size_t id_len, void *data, u_int8_t **cert, return 0; } - sprintf (file, "%s/%s/%s", dirname, addr_str, CREDENTIAL_FILE); + snprintf (file, len + strlen (addr_str), "%s/%s/%s", dirname, addr_str, + CREDENTIAL_FILE); free (addr_str); break; @@ -2082,9 +2083,10 @@ keynote_cert_obtain (u_int8_t *id, size_t id_len, void *data, u_int8_t **cert, return 0; } - sprintf (file, "%s/", dirname); - memcpy (file + strlen (file), id, id_len); - sprintf (file + strlen (dirname) + 1 + id_len, "/%s", CREDENTIAL_FILE); + snprintf (file, len + id_len, "%s/", dirname); + memcpy (file + strlen (dirname) + 1, id, id_len); + snprintf (file + strlen (dirname) + 1 + id_len, + len - strlen (dirname) - 1, "/%s", CREDENTIAL_FILE); break; } diff --git a/sbin/isakmpd/x509.c b/sbin/isakmpd/x509.c index 44b8dfe5e48..96d18b698ff 100644 --- a/sbin/isakmpd/x509.c +++ b/sbin/isakmpd/x509.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509.c,v 1.66 2002/01/03 09:24:02 ho Exp $ */ +/* $OpenBSD: x509.c,v 1.67 2002/01/23 17:26:21 ho Exp $ */ /* $EOM: x509.c,v 1.54 2001/01/16 18:42:16 ho Exp $ */ /* @@ -125,7 +125,7 @@ x509_generate_kn (int id, X509 *cert) char before[15], after[15]; ASN1_TIME *tm; char *timecomp, *timecomp2; - int i; + int i, buf_len; LOG_DBG ((LOG_POLICY, 90, "x509_generate_kn: generating KeyNote policy for certificate %p", @@ -224,8 +224,9 @@ x509_generate_kn (int id, X509 *cert) } LC (RSA_free, (key)); - buf = calloc (strlen (fmt) + strlen (ikey) + strlen (skey) + 56, - sizeof (char)); + buf_len = strlen (fmt) + strlen (ikey) + strlen (skey) + 56; + buf = calloc (buf_len, sizeof (char)); + buf_len *= sizeof (char); if (!buf) { log_error ("x509_generate_kn: " @@ -301,9 +302,9 @@ x509_generate_kn (int id, X509 *cert) /* Stupid UTC tricks. */ if (tm->data[0] < '5') - sprintf (before, "20%s", tm->data); + snprintf (before, 15, "20%s", tm->data); else - sprintf (before, "19%s", tm->data); + snprintf (before, 15, "19%s", tm->data); } else { /* V_ASN1_GENERICTIME */ @@ -336,7 +337,7 @@ x509_generate_kn (int id, X509 *cert) return 0; } - sprintf (before, "%s", tm->data); + snprintf (before, 15, "%s", tm->data); } /* Fix missing seconds. */ @@ -417,9 +418,9 @@ x509_generate_kn (int id, X509 *cert) /* Stupid UTC tricks. */ if (tm->data[0] < '5') - sprintf (after, "20%s", tm->data); + snprintf (after, 15, "20%s", tm->data); else - sprintf (after, "19%s", tm->data); + snprintf (after, 15, "19%s", tm->data); } else { /* V_ASN1_GENERICTIME */ @@ -452,7 +453,7 @@ x509_generate_kn (int id, X509 *cert) return 0; } - sprintf (after, "%s", tm->data); + snprintf (after, 15, "%s", tm->data); } /* Fix missing seconds. */ @@ -465,7 +466,7 @@ x509_generate_kn (int id, X509 *cert) after[14] = '\0'; /* This will overwrite trailing 'Z' */ } - sprintf (buf, fmt, skey, ikey, timecomp, before, timecomp2, after); + snprintf (buf, buf_len, fmt, skey, ikey, timecomp, before, timecomp2, after); free (ikey); free (skey); @@ -497,15 +498,16 @@ x509_generate_kn (int id, X509 *cert) return 0; } - buf = malloc (strlen (fmt2) + strlen (isname) + strlen (subname) + 56); + buf_len = strlen (fmt2) + strlen (isname) + strlen (subname) + 56; + buf = malloc (buf_len); if (!buf) { - log_error ("x509_generate_kn: malloc (%d) failed", strlen (fmt2) + - strlen (isname) + strlen (subname) + 56); + log_error ("x509_generate_kn: malloc (%d) failed", buf_len); return 0; } - sprintf (buf, fmt2, isname, subname, timecomp, before, timecomp2, after); + snprintf (buf, buf_len, fmt2, isname, subname, timecomp, before, timecomp2, + after); if (LK (kn_add_assertion, (id, buf, strlen (buf), ASSERT_FLAG_LOCAL)) == -1) @@ -683,15 +685,13 @@ x509_read_from_dir (X509_STORE *ctx, char *name, int hash) return 0; } - strncpy (fullname, name, sizeof fullname - 1); - fullname[sizeof fullname - 1] = 0; + strlcpy (fullname, name, sizeof fullname); off = strlen (fullname); - size = sizeof fullname - off - 1; + size = sizeof fullname - off; while ((file = readdir (dir)) != NULL) { - strncpy (fullname + off, file->d_name, size); - fullname[off + size] = 0; + strlcpy (fullname + off, file->d_name, size); if (file->d_type != DT_UNKNOWN) { |