diff options
Diffstat (limited to 'src/lib/libtls/tls_util.c')
-rw-r--r-- | src/lib/libtls/tls_util.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/lib/libtls/tls_util.c b/src/lib/libtls/tls_util.c index aaa3eef49f..f9df287ca8 100644 --- a/src/lib/libtls/tls_util.c +++ b/src/lib/libtls/tls_util.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls_util.c,v 1.9 2017/06/22 18:03:57 jsing Exp $ */ | 1 | /* $OpenBSD: tls_util.c,v 1.10 2018/02/05 00:52:24 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> | 4 | * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> |
@@ -43,7 +43,7 @@ tls_host_port(const char *hostport, char **host, char **port) | |||
43 | *port = NULL; | 43 | *port = NULL; |
44 | 44 | ||
45 | if ((s = strdup(hostport)) == NULL) | 45 | if ((s = strdup(hostport)) == NULL) |
46 | goto fail; | 46 | goto err; |
47 | 47 | ||
48 | h = p = s; | 48 | h = p = s; |
49 | 49 | ||
@@ -66,14 +66,14 @@ tls_host_port(const char *hostport, char **host, char **port) | |||
66 | *p++ = '\0'; | 66 | *p++ = '\0'; |
67 | 67 | ||
68 | if (asprintf(host, "%s", h) == -1) | 68 | if (asprintf(host, "%s", h) == -1) |
69 | goto fail; | 69 | goto err; |
70 | if (asprintf(port, "%s", p) == -1) | 70 | if (asprintf(port, "%s", p) == -1) |
71 | goto fail; | 71 | goto err; |
72 | 72 | ||
73 | rv = 0; | 73 | rv = 0; |
74 | goto done; | 74 | goto done; |
75 | 75 | ||
76 | fail: | 76 | err: |
77 | free(*host); | 77 | free(*host); |
78 | *host = NULL; | 78 | *host = NULL; |
79 | free(*port); | 79 | free(*port); |
@@ -126,38 +126,38 @@ tls_load_file(const char *name, size_t *len, char *password) | |||
126 | /* Just load the file into memory without decryption */ | 126 | /* Just load the file into memory without decryption */ |
127 | if (password == NULL) { | 127 | if (password == NULL) { |
128 | if (fstat(fd, &st) != 0) | 128 | if (fstat(fd, &st) != 0) |
129 | goto fail; | 129 | goto err; |
130 | if (st.st_size < 0) | 130 | if (st.st_size < 0) |
131 | goto fail; | 131 | goto err; |
132 | size = (size_t)st.st_size; | 132 | size = (size_t)st.st_size; |
133 | if ((buf = malloc(size)) == NULL) | 133 | if ((buf = malloc(size)) == NULL) |
134 | goto fail; | 134 | goto err; |
135 | n = read(fd, buf, size); | 135 | n = read(fd, buf, size); |
136 | if (n < 0 || (size_t)n != size) | 136 | if (n < 0 || (size_t)n != size) |
137 | goto fail; | 137 | goto err; |
138 | close(fd); | 138 | close(fd); |
139 | goto done; | 139 | goto done; |
140 | } | 140 | } |
141 | 141 | ||
142 | /* Or read the (possibly) encrypted key from file */ | 142 | /* Or read the (possibly) encrypted key from file */ |
143 | if ((fp = fdopen(fd, "r")) == NULL) | 143 | if ((fp = fdopen(fd, "r")) == NULL) |
144 | goto fail; | 144 | goto err; |
145 | fd = -1; | 145 | fd = -1; |
146 | 146 | ||
147 | key = PEM_read_PrivateKey(fp, NULL, tls_password_cb, password); | 147 | key = PEM_read_PrivateKey(fp, NULL, tls_password_cb, password); |
148 | fclose(fp); | 148 | fclose(fp); |
149 | if (key == NULL) | 149 | if (key == NULL) |
150 | goto fail; | 150 | goto err; |
151 | 151 | ||
152 | /* Write unencrypted key to memory buffer */ | 152 | /* Write unencrypted key to memory buffer */ |
153 | if ((bio = BIO_new(BIO_s_mem())) == NULL) | 153 | if ((bio = BIO_new(BIO_s_mem())) == NULL) |
154 | goto fail; | 154 | goto err; |
155 | if (!PEM_write_bio_PrivateKey(bio, key, NULL, NULL, 0, NULL, NULL)) | 155 | if (!PEM_write_bio_PrivateKey(bio, key, NULL, NULL, 0, NULL, NULL)) |
156 | goto fail; | 156 | goto err; |
157 | if ((size = BIO_get_mem_data(bio, &data)) <= 0) | 157 | if ((size = BIO_get_mem_data(bio, &data)) <= 0) |
158 | goto fail; | 158 | goto err; |
159 | if ((buf = malloc(size)) == NULL) | 159 | if ((buf = malloc(size)) == NULL) |
160 | goto fail; | 160 | goto err; |
161 | memcpy(buf, data, size); | 161 | memcpy(buf, data, size); |
162 | 162 | ||
163 | BIO_free_all(bio); | 163 | BIO_free_all(bio); |
@@ -167,7 +167,7 @@ tls_load_file(const char *name, size_t *len, char *password) | |||
167 | *len = size; | 167 | *len = size; |
168 | return (buf); | 168 | return (buf); |
169 | 169 | ||
170 | fail: | 170 | err: |
171 | if (fd != -1) | 171 | if (fd != -1) |
172 | close(fd); | 172 | close(fd); |
173 | freezero(buf, size); | 173 | freezero(buf, size); |