]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3435] fix a crash on empty notification tree
authorAndrei Pavel <andrei@isc.org>
Thu, 20 Jun 2024 18:11:33 +0000 (21:11 +0300)
committerAndrei Pavel <andrei@isc.org>
Thu, 20 Jun 2024 18:29:58 +0000 (21:29 +0300)
... and a message containing two "%1"s.

src/bin/netconf/netconf.cc
src/bin/netconf/netconf_messages.cc
src/bin/netconf/netconf_messages.mes

index 331034485989c4567150326aae29e179cc23190d..d66c3139a2745b3dba0952845bba0f4dbfc90611 100644 (file)
@@ -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<string_view> /* sub_xpath */,
-                                     Event event,
-                                     uint32_t /* request_id */) {
+    sysrepo::ErrorCode moduleChange(Session sess,
+                                    uint32_t /* subscription_id */,
+                                    string_view module_name,
+                                    optional<string_view> /* 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<DataNode> const notification_tree,
-                     NotificationTimeStamp const /* timestamp */) {
+    void eventNotif(Session /* session */,
+                    uint32_t /* subscription_id */,
+                    NotificationType const notification_type,
+                    optional<DataNode> const notification_tree,
+                    NotificationTimeStamp const /* timestamp */) {
         string n;
         switch (notification_type) {
         case NotificationType::Realtime:
@@ -127,9 +127,14 @@ public:
             break;
         }
 
-        optional<string> const str(
-            notification_tree->printStr(DataFormat::JSON, PrintFlags::WithDefaultsExplicit));
-        string const tree(str ? *str : string());
+        string tree;
+        if (notification_tree) {
+            optional<string> 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<DataNode> 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) {
index a5b0f28bd6e1f078f69413f29aebce3491ae7d40..baac6ceeea434ea75d896eb86fe746f5b95bcdba 100644 (file)
@@ -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",
index ea601b3bc55319d6af11ed43ea311dbbab40b754..f984a6d18304a232a2e85e677c073f3f502837bc 100644 (file)
@@ -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