summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Svensson <anders@erlang.org>2019-05-17 08:51:08 +0200
committerAnders Svensson <anders@erlang.org>2019-06-03 14:47:52 +0200
commitbe4fb40693928476c616b8cb0d8e097c965a83ca (patch)
tree22dcd5c38d4667bcb20b17374175c635d9075bf5
parent596dc20ccd0613c664063ea90c602cb0ad46bfac (diff)
downloaderlang-be4fb40693928476c616b8cb0d8e097c965a83ca.tar.gz
Handle reception of invalid session-id
RFC 6241 says the following in 8.1 Capabilities Exchange. A server sending the <hello> element MUST include a <session-id> element containing the session ID for this NETCONF session. A client sending the <hello> element MUST NOT include a <session-id> element. A server receiving a <hello> message with a <session-id> element MUST terminate the NETCONF session. Similarly, a client that does not receive a <session-id> element in the server's <hello> message MUST terminate the NETCONF session (without first sending a <close-session>). This doesn't say anything about the type of session-id, but the XML schema in Appendix B defines it as a positive integer, and receiving an invalid value is reasonably equivalent to not receiving the element at all.
-rw-r--r--lib/common_test/src/ct_netconfc.erl38
1 files changed, 22 insertions, 16 deletions
diff --git a/lib/common_test/src/ct_netconfc.erl b/lib/common_test/src/ct_netconfc.erl
index bd1c993962..6ce0ed1a27 100644
--- a/lib/common_test/src/ct_netconfc.erl
+++ b/lib/common_test/src/ct_netconfc.erl
@@ -1687,24 +1687,30 @@ get_all_xmlns_attrs([],XmlnsAttrs) ->
XmlnsAttrs.
%% Decode server hello to pick out session id and capabilities
-decode_hello({hello,_Attrs,Hello}) ->
- case lists:keyfind('session-id',1,Hello) of
- {'session-id',_,[SessionId]} ->
- case lists:keyfind(capabilities,1,Hello) of
- {capabilities,_,Capabilities} ->
- case decode_caps(Capabilities,[],false) of
- {ok,Caps} ->
- {ok,list_to_integer(SessionId),Caps};
- Error ->
- Error
- end;
- false ->
- {error,{incorrect_hello,capabilities_not_found}}
- end;
- false ->
- {error,{incorrect_hello,no_session_id_found}}
+decode_hello({hello, _Attrs, Hello}) ->
+ U = make_ref(),
+ try
+ [{'session-id', _, [SessionId]}, _ | _]
+ = [find('session-id', Hello), no_session_id_found | U],
+ [{ok, Id}, _ | _]
+ = [catch {ok, list_to_integer(SessionId)}, invalid_session_id | U],
+ [true, _ | _]
+ = [0 < Id, invalid_session_id | U],
+ [{capabilities, _, Capabilities}, _ | _]
+ = [find(capabilities, Hello), capabilities_not_found | U],
+ [{ok, Caps}, _ | _]
+ = [decode_caps(Capabilities, [], false), false | U],
+ {ok, Id, Caps}
+ catch
+ error: {badmatch, [Error, false | U]} ->
+ Error;
+ error: {badmatch, [_, Reason | U]} ->
+ {error, {incorrect_hello, Reason}}
end.
+find(Key, List) ->
+ lists:keyfind(Key, 1, List).
+
decode_caps([{capability, [], [?NETCONF_BASE_CAP ++ _ = Cap]} | Caps],
Acc,
_) ->