From 0da7130a1ace84869742521bac5831d1f5d183e5 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Tue, 17 Mar 2020 21:35:56 -0400 Subject: [PATCH] Protect against args being modified --- nomad/node_endpoint.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nomad/node_endpoint.go b/nomad/node_endpoint.go index f635abc27..e26891349 100644 --- a/nomad/node_endpoint.go +++ b/nomad/node_endpoint.go @@ -78,11 +78,12 @@ type Node struct { // Register is used to upsert a client that is available for scheduling func (n *Node) Register(args *structs.NodeRegisterRequest, reply *structs.NodeUpdateResponse) error { + isForwarded := args.IsForwarded() if done, err := n.srv.forward("Node.Register", args, args, reply); done { // We have a valid node connection since there is no error from the // forwarded server, so add the mapping to cache the // connection and allow the server to send RPCs to the client. - if err == nil && n.ctx != nil && n.ctx.NodeID == "" && !args.IsForwarded() { + if err == nil && n.ctx != nil && n.ctx.NodeID == "" && !isForwarded { n.ctx.NodeID = args.Node.ID n.srv.addNodeConn(n.ctx) } @@ -370,11 +371,12 @@ func (n *Node) deregister(args *structs.NodeBatchDeregisterRequest, // UpdateStatus is used to update the status of a client node func (n *Node) UpdateStatus(args *structs.NodeUpdateStatusRequest, reply *structs.NodeUpdateResponse) error { + isForwarded := args.IsForwarded() if done, err := n.srv.forward("Node.UpdateStatus", args, args, reply); done { // We have a valid node connection since there is no error from the // forwarded server, so add the mapping to cache the // connection and allow the server to send RPCs to the client. - if err == nil && n.ctx != nil && n.ctx.NodeID == "" && !args.IsForwarded() { + if err == nil && n.ctx != nil && n.ctx.NodeID == "" && !isForwarded { n.ctx.NodeID = args.NodeID n.srv.addNodeConn(n.ctx) } @@ -921,11 +923,12 @@ func (n *Node) GetAllocs(args *structs.NodeSpecificRequest, // per allocation. func (n *Node) GetClientAllocs(args *structs.NodeSpecificRequest, reply *structs.NodeClientAllocsResponse) error { + isForwarded := args.IsForwarded() if done, err := n.srv.forward("Node.GetClientAllocs", args, args, reply); done { // We have a valid node connection since there is no error from the // forwarded server, so add the mapping to cache the // connection and allow the server to send RPCs to the client. - if err == nil && n.ctx != nil && n.ctx.NodeID == "" && !args.IsForwarded() { + if err == nil && n.ctx != nil && n.ctx.NodeID == "" && !isForwarded { n.ctx.NodeID = args.NodeID n.srv.addNodeConn(n.ctx) }