diff options
-rw-r--r-- | src/or/torcert.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/or/torcert.c b/src/or/torcert.c index 596cd2be31..ef5b4c0c3b 100644 --- a/src/or/torcert.c +++ b/src/or/torcert.c @@ -206,7 +206,11 @@ tor_cert_checksig(tor_cert_t *cert, return -1; } else { cert->sig_ok = 1; - memcpy(cert->signing_key.pubkey, checkable.pubkey->pubkey, 32); + /* Only copy the checkable public key when it is different from the signing + * key of the certificate to avoid undefined behavior. */ + if (cert->signing_key.pubkey != checkable.pubkey->pubkey) { + memcpy(cert->signing_key.pubkey, checkable.pubkey->pubkey, 32); + } cert->cert_valid = 1; return 0; } |