Compare commits

...

2 Commits

Author SHA1 Message Date
Félix Baylac Jacqué a3e4418ebd IsValidPath: implement request parser. 2023-09-15 14:18:27 +02:00
Félix Baylac Jacqué 05585f85fc read string: fix out of bound bug
When the bytestring we were about to copy was at the end of the TVB,
we were outrunning the original buffer by trying to read "size + 1".

Stopping the read at size, then expending the newly created bytestring
instead.
2023-09-15 14:16:44 +02:00
1 changed files with 16 additions and 1 deletions

View File

@ -36,6 +36,8 @@ local op_setoptions_nbclientoverrides = ProtoField.uint64("nix.setoptions.nbclie
local op_setoptions_clientoverridename = ProtoField.uint64("nix.setoptions.clientoverridename", "Client Override key")
local op_setoptions_clientoverridevalue = ProtoField.uint64("nix.setoptions.clientoverridevalue", "Client Override Value")
local op_is_valid_path = ProtoField.string("nix.isvalidpath", "isvalidpath request")
op_addtostore_step = 0
nix_proto.fields = {
@ -72,6 +74,8 @@ nix_proto.fields = {
op_setoptions_nbclientoverrides,
op_setoptions_clientoverridename,
op_setoptions_clientoverridevalue,
op_is_valid_path
}
local op_table = {
@ -169,7 +173,8 @@ function read_string(tvb, pinfo, tree, offset)
-- Note: the offset indexes the original tvb, not the
-- temporarily created one. There's no need to take this new
-- null bit into account.
local tvb_clone = tvb:bytes(offset, size + 1)
local tvb_clone = tvb:bytes(offset, size)
tvb_clone:set_size(size + 1)
tvb_clone:set_index(size, 0)
str = tvb_clone(0,size+1):tvb():range(0,size+1):string()
offset = offset + size
@ -275,6 +280,14 @@ function parse_set_options(tvb, pinfo, tree, offset)
return offset
end
function parse_is_valid_path(tvb, pinfo, tree, offset)
local initoffset = offset
local path
offset, path = read_string(tvb, pinfo, tree, offset)
tree:add(op_is_valid_path, tvb(initoffset, offset - initoffset), path)
return offset
end
function parse_op(tvb, pinfo, tree, offset, op)
tree:add(op_name_field, tvb(offset, 8), op_table[op])
offset = offset + 8
@ -283,6 +296,8 @@ function parse_op(tvb, pinfo, tree, offset, op)
offset = parse_add_to_store(tvb, pinfo, tree, offset)
elseif op_table[op] == "SetOptions" then
offset = parse_set_options(tvb, pinfo, tree, offset)
elseif op_table[op] == "IsValidPath" then
offset = parse_is_valid_path(tvb, pinfo, tree, offset)
end
return offset
end