Skip to content

Commit f4cf5d1

Browse files
bluhmtobhe
authored andcommitted
Fix a double-free in iked(8) and isakmpd(8) in ecdh mode.
from markus@; OK tobhe@ tb@
1 parent 4259b54 commit f4cf5d1

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

iked/dh.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: dh.c,v 1.33 2023/07/28 07:31:38 claudio Exp $ */
1+
/* $OpenBSD: dh.c,v 1.34 2025/04/09 07:10:48 bluhm Exp $ */
22

33
/*
44
* Copyright (c) 2020-2021 Tobias Heider <tobhe@openbsd.org>
@@ -671,9 +671,9 @@ ec_raw2point(struct dh_group *group, uint8_t *buf, size_t len)
671671
{
672672
const EC_GROUP *ecgroup = NULL;
673673
EC_POINT *point = NULL;
674+
EC_POINT *ret = NULL;
674675
BN_CTX *bnctx = NULL;
675676
BIGNUM *x = NULL, *y = NULL;
676-
int ret = -1;
677677
size_t eclen;
678678
size_t xlen, ylen;
679679

@@ -701,10 +701,12 @@ ec_raw2point(struct dh_group *group, uint8_t *buf, size_t len)
701701
if (!EC_POINT_set_affine_coordinates(ecgroup, point, x, y, bnctx))
702702
goto done;
703703

704-
ret = 0;
704+
/* success */
705+
ret = point;
706+
point = NULL; /* owned by caller */
707+
705708
done:
706-
if (ret != 0 && point != NULL)
707-
EC_POINT_clear_free(point);
709+
EC_POINT_clear_free(point);
708710
/* Make sure to erase sensitive data */
709711
if (x != NULL)
710712
BN_clear(x);
@@ -713,7 +715,7 @@ ec_raw2point(struct dh_group *group, uint8_t *buf, size_t len)
713715
BN_CTX_end(bnctx);
714716
BN_CTX_free(bnctx);
715717

716-
return (point);
718+
return (ret);
717719
}
718720

719721
int

0 commit comments

Comments
 (0)