Skip to content

Commit 86607af

Browse files
committed
tlshd: Store peer IDs in a GArray
The number of peer IDs passed up from the kernel is not known in advance. Use a flexible array to handle one-at-a-time storage of the peerids as they are retrieved from the netlink arguments. Signed-off-by: Chuck Lever <[email protected]>
1 parent 1e03c0e commit 86607af

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

src/tlshd/client.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,10 @@ static void tlshd_tls13_client_psk_handshake_one(struct tlshd_handshake_parms *p
417417

418418
static void tlshd_tls13_client_psk_handshake(struct tlshd_handshake_parms *parms)
419419
{
420-
unsigned int i;
420+
key_serial_t peerid;
421+
guint i;
421422

422-
if (!parms->peerids) {
423+
if (parms->peerids->len == 0) {
423424
tlshd_log_error("No key identities");
424425
return;
425426
}
@@ -428,8 +429,9 @@ static void tlshd_tls13_client_psk_handshake(struct tlshd_handshake_parms *parms
428429
* GnuTLS does not yet support multiple offered PskIdentities.
429430
* Retry ClientHello with each identity on the kernel's list.
430431
*/
431-
for (i = 0; i < parms->num_peerids; i++) {
432-
tlshd_tls13_client_psk_handshake_one(parms, parms->peerids[i]);
432+
for (i = 0; i < parms->peerids->len; i++) {
433+
peerid = g_array_index(parms->peerids, key_serial_t, i);
434+
tlshd_tls13_client_psk_handshake_one(parms, peerid);
433435
if (parms->session_status != EACCES)
434436
break;
435437
}

src/tlshd/netlink.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,15 @@ void tlshd_genl_dispatch(void)
189189
static void tlshd_parse_peer_identity(struct tlshd_handshake_parms *parms,
190190
struct nlattr *head)
191191
{
192+
key_serial_t peerid;
193+
192194
if (!head) {
193195
tlshd_log_debug("No peer identities found\n");
194196
return;
195197
}
196198

197-
parms->num_peerids = 1;
198-
199-
parms->peerids = calloc(parms->num_peerids, sizeof(key_serial_t));
200-
if (!parms->peerids) {
201-
parms->num_peerids = 0;
202-
return;
203-
}
204-
205-
parms->peerids[0] = nla_get_s32(head);
199+
peerid = nla_get_s32(head);
200+
g_array_append_val(parms->peerids, peerid);
206201
}
207202

208203
#if LIBNL_VER_NUM >= LIBNL_VER(3,5)
@@ -320,7 +315,6 @@ static const struct tlshd_handshake_parms tlshd_default_handshake_parms = {
320315
.x509_cert = TLS_NO_CERT,
321316
.x509_privkey = TLS_NO_PRIVKEY,
322317
.peerids = NULL,
323-
.num_peerids = 0,
324318
.remote_peerids = NULL,
325319
.msg_status = 0,
326320
.session_status = EIO,
@@ -346,6 +340,7 @@ int tlshd_genl_get_handshake_parms(struct tlshd_handshake_parms *parms)
346340

347341
*parms = tlshd_default_handshake_parms;
348342

343+
parms->peerids = g_array_new(FALSE, FALSE, sizeof(key_serial_t));
349344
parms->remote_peerids = g_array_new(FALSE, FALSE, sizeof(key_serial_t));
350345

351346
ret = tlshd_genl_sock_open(&nls);
@@ -415,7 +410,7 @@ void tlshd_genl_put_handshake_parms(struct tlshd_handshake_parms *parms)
415410
{
416411
if (parms->keyring)
417412
keyctl_unlink(parms->keyring, KEY_SPEC_SESSION_KEYRING);
418-
free(parms->peerids);
413+
g_array_free(parms->peerids, TRUE);
419414
g_array_free(parms->remote_peerids, TRUE);
420415
}
421416

src/tlshd/tlshd.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ struct tlshd_handshake_parms {
3939
key_serial_t keyring;
4040
key_serial_t x509_cert;
4141
key_serial_t x509_privkey;
42-
key_serial_t *peerids;
43-
unsigned int num_peerids;
42+
GArray *peerids;
4443
GArray *remote_peerids;
4544
int msg_status;
4645

0 commit comments

Comments
 (0)