Skip to content

Commit 6cee2af

Browse files
authored
Check number of keys in EVAL/EVALSHA (#1067)
Return correct type in SCRIPT EXISTS Co-authored-by: prvyk <github@privatemail.fastmailbox.net>
1 parent 9e1427e commit 6cee2af

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

libs/server/Lua/LuaCommands.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// Licensed under the MIT license.
33

44
using System;
5-
using System.Collections.Generic;
65
using Garnet.common;
76
using Microsoft.Extensions.Logging;
8-
using Tsavorite.core;
97

108
namespace Garnet.server
119
{
@@ -28,6 +26,11 @@ private unsafe bool TryEVALSHA()
2826
return AbortWithWrongNumberOfArguments("EVALSHA");
2927
}
3028

29+
if (!parseState.TryGetInt(1, out var n) || (n < 0) || (n > count - 2))
30+
{
31+
return AbortWithErrorMessage(CmdStrings.RESP_ERR_GENERIC_VALUE_IS_NOT_INTEGER);
32+
}
33+
3134
ref var digest = ref parseState.GetArgSliceByRef(0);
3235

3336
var convertedToLower = false;
@@ -99,6 +102,11 @@ private unsafe bool TryEVAL()
99102
return AbortWithWrongNumberOfArguments("EVAL");
100103
}
101104

105+
if (!parseState.TryGetInt(1, out var n) || (n < 0) || (n > count - 2))
106+
{
107+
return AbortWithErrorMessage(CmdStrings.RESP_ERR_GENERIC_VALUE_IS_NOT_INTEGER);
108+
}
109+
102110
ref var script = ref parseState.GetArgSliceByRef(0);
103111

104112
// that this is stack allocated is load bearing - if it moves, things will break
@@ -162,7 +170,7 @@ private bool NetworkScriptExists()
162170
exists = storeWrapper.storeScriptCache.ContainsKey(sha1Arg) ? 1 : 0;
163171
}
164172

165-
while (!RespWriteUtils.TryWriteArrayItem(exists, ref dcurr, dend))
173+
while (!RespWriteUtils.TryWriteInt32(exists, ref dcurr, dend))
166174
SendAndReset();
167175
}
168176

0 commit comments

Comments
 (0)