Fix TokenSign copying and using uninitialized arena

TokenSign was copying unused Arena held by Standalone instead of refering to it.
An Arena has to be used at least once before it holds a valid, copyable reference.
Otherwise the lifecycle of the copied Arena would be its own and not be shared with the original.
Thus, when the copied arena went out of scope,
the memory supposed to be held by returned Standalone also got released.

Fix: instead of copying, refer to Standalone's arena.
This commit is contained in:
Junhyun Shim 2022-05-02 09:48:43 +02:00
parent 0ca9761088
commit 41d1c73b9c
1 changed files with 2 additions and 2 deletions

View File

@ -114,7 +114,7 @@ Standalone<KeyPairRef> generateEcdsaKeyPair() {
Standalone<SignedAuthTokenRef> signToken(AuthTokenRef token, StringRef keyName, StringRef privateKeyDer) {
auto ret = Standalone<SignedAuthTokenRef>{};
auto arena = ret.arena();
auto& arena = ret.arena();
auto writer = ObjectWriter([&arena](size_t len) { return new (arena) uint8_t[len]; }, IncludeVersion());
writer.serialize(token);
auto tokenStr = writer.toStringRef();
@ -181,7 +181,7 @@ TEST_CASE("/fdbrpc/TokenSign") {
for (auto i = 0; i < numIters; i++) {
auto keyPair = generateEcdsaKeyPair();
auto token = Standalone<AuthTokenRef>{};
auto arena = token.arena();
auto& arena = token.arena();
auto& rng = *deterministicRandom();
token.expiresAt = timer_monotonic() * (0.5 + rng.random01());
if (auto setIp = rng.randomInt(0, 3)) {