From: Andrei Pavel Date: Thu, 20 Jun 2024 18:11:33 +0000 (+0300) Subject: [#3435] fix a crash on empty notification tree X-Git-Tag: Kea-2.7.0~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b55f11ccc4dfc5f2ecde7856d993821be531186;p=thirdparty%2Fkea.git [#3435] fix a crash on empty notification tree ... and a message containing two "%1"s. --- diff --git a/src/bin/netconf/netconf.cc b/src/bin/netconf/netconf.cc index 3310344859..d66c3139a2 100644 --- a/src/bin/netconf/netconf.cc +++ b/src/bin/netconf/netconf.cc @@ -52,12 +52,12 @@ public: /// @param event The event. /// @param private_ctx The private context. /// @return the sysrepo return code. - sysrepo::ErrorCode module_change(Session sess, - uint32_t /* subscription_id */, - string_view module_name, - optional /* sub_xpath */, - Event event, - uint32_t /* request_id */) { + sysrepo::ErrorCode moduleChange(Session sess, + uint32_t /* subscription_id */, + string_view module_name, + optional /* sub_xpath */, + Event event, + uint32_t /* request_id */) { ostringstream event_type; switch (event) { case Event::Update: @@ -97,11 +97,11 @@ public: } } - void event_notif(Session /* session */, - uint32_t /* subscription_id */, - NotificationType const notification_type, - optional const notification_tree, - NotificationTimeStamp const /* timestamp */) { + void eventNotif(Session /* session */, + uint32_t /* subscription_id */, + NotificationType const notification_type, + optional const notification_tree, + NotificationTimeStamp const /* timestamp */) { string n; switch (notification_type) { case NotificationType::Realtime: @@ -127,9 +127,14 @@ public: break; } - optional const str( - notification_tree->printStr(DataFormat::JSON, PrintFlags::WithDefaultsExplicit)); - string const tree(str ? *str : string()); + string tree; + if (notification_tree) { + optional const str( + notification_tree->printStr(DataFormat::JSON, PrintFlags::WithDefaultsExplicit)); + if (str) { + tree = *str; + } + } LOG_INFO(netconf_logger, NETCONF_NOTIFICATION_RECEIVED) .arg(n) .arg(service_pair_.first) @@ -440,8 +445,8 @@ NetconfAgent::subscribeToDataChanges(const CfgServersMapPair& service_pair) { Event event, uint32_t request_id) { NetconfAgentCallback agent(service_pair); - return agent.module_change(session, subscription_id, module_name, sub_xpath, event, - request_id); + return agent.moduleChange(session, subscription_id, module_name, sub_xpath, event, + request_id); }; try { SubscribeOptions options(SubscribeOptions::Default); @@ -490,8 +495,8 @@ NetconfAgent::subscribeToNotifications(const CfgServersMapPair& service_pair) { optional const notification_tree, NotificationTimeStamp const timestamp) { NetconfAgentCallback agent(service_pair); - return agent.event_notif(session, subscription_id, notification_type, notification_tree, - timestamp); + return agent.eventNotif(session, subscription_id, notification_type, notification_tree, + timestamp); }; try { auto exception_handler = [model](std::exception& ex) { diff --git a/src/bin/netconf/netconf_messages.cc b/src/bin/netconf/netconf_messages.cc index a5b0f28bd6..baac6ceeea 100644 --- a/src/bin/netconf/netconf_messages.cc +++ b/src/bin/netconf/netconf_messages.cc @@ -67,7 +67,7 @@ const char* values[] = { "NETCONF_MODULE_REVISION_ERR", "Essential module %1 does NOT have the right revision: expected %2, got %3", "NETCONF_MODULE_REVISION_WARN", "Module %1 does NOT have the right revision: expected %2, got %3", "NETCONF_NOTIFICATION_INTERNAL_ERROR", "an internal error occurred while sending an event notification for module %1: %2", - "NETCONF_NOTIFICATION_RECEIVED", "Received notification of type %1 for module %1: %2", + "NETCONF_NOTIFICATION_RECEIVED", "Received notification of type %1 for module %2: '%3'", "NETCONF_NOT_SUBSCRIBED_TO_NOTIFICATIONS", "subscribing to notifications for %1 server with %2 module failed: %3", "NETCONF_RUN_EXIT", "application is exiting the event loop", "NETCONF_SET_CONFIG", "set configuration to %1 server: %2", diff --git a/src/bin/netconf/netconf_messages.mes b/src/bin/netconf/netconf_messages.mes index ea601b3bc5..f984a6d183 100644 --- a/src/bin/netconf/netconf_messages.mes +++ b/src/bin/netconf/netconf_messages.mes @@ -85,7 +85,7 @@ The error message indicates that kea-netconf got an error while sysrepo was send This error is not fatal and can be recovered from. The name of the module and the internal error message are printed. -% NETCONF_NOTIFICATION_RECEIVED Received notification of type %1 for module %1: %2 +% NETCONF_NOTIFICATION_RECEIVED Received notification of type %1 for module %2: '%3' This informational message logs any YANG notification that has been signaled by the server, sent to kea-netconf which then was forwarded to subscribed clients. To achieve this, kea-netconf subscribes itself as a client to all