Skip to content

Commit 2b55f11

Browse files
committed
[#3435] fix a crash on empty notification tree
... and a message containing two "%1"s.
1 parent e897808 commit 2b55f11

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

src/bin/netconf/netconf.cc

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ class NetconfAgentCallback {
5252
/// @param event The event.
5353
/// @param private_ctx The private context.
5454
/// @return the sysrepo return code.
55-
sysrepo::ErrorCode module_change(Session sess,
56-
uint32_t /* subscription_id */,
57-
string_view module_name,
58-
optional<string_view> /* sub_xpath */,
59-
Event event,
60-
uint32_t /* request_id */) {
55+
sysrepo::ErrorCode moduleChange(Session sess,
56+
uint32_t /* subscription_id */,
57+
string_view module_name,
58+
optional<string_view> /* sub_xpath */,
59+
Event event,
60+
uint32_t /* request_id */) {
6161
ostringstream event_type;
6262
switch (event) {
6363
case Event::Update:
@@ -97,11 +97,11 @@ class NetconfAgentCallback {
9797
}
9898
}
9999

100-
void event_notif(Session /* session */,
101-
uint32_t /* subscription_id */,
102-
NotificationType const notification_type,
103-
optional<DataNode> const notification_tree,
104-
NotificationTimeStamp const /* timestamp */) {
100+
void eventNotif(Session /* session */,
101+
uint32_t /* subscription_id */,
102+
NotificationType const notification_type,
103+
optional<DataNode> const notification_tree,
104+
NotificationTimeStamp const /* timestamp */) {
105105
string n;
106106
switch (notification_type) {
107107
case NotificationType::Realtime:
@@ -127,9 +127,14 @@ class NetconfAgentCallback {
127127
break;
128128
}
129129

130-
optional<string> const str(
131-
notification_tree->printStr(DataFormat::JSON, PrintFlags::WithDefaultsExplicit));
132-
string const tree(str ? *str : string());
130+
string tree;
131+
if (notification_tree) {
132+
optional<string> const str(
133+
notification_tree->printStr(DataFormat::JSON, PrintFlags::WithDefaultsExplicit));
134+
if (str) {
135+
tree = *str;
136+
}
137+
}
133138
LOG_INFO(netconf_logger, NETCONF_NOTIFICATION_RECEIVED)
134139
.arg(n)
135140
.arg(service_pair_.first)
@@ -440,8 +445,8 @@ NetconfAgent::subscribeToDataChanges(const CfgServersMapPair& service_pair) {
440445
Event event,
441446
uint32_t request_id) {
442447
NetconfAgentCallback agent(service_pair);
443-
return agent.module_change(session, subscription_id, module_name, sub_xpath, event,
444-
request_id);
448+
return agent.moduleChange(session, subscription_id, module_name, sub_xpath, event,
449+
request_id);
445450
};
446451
try {
447452
SubscribeOptions options(SubscribeOptions::Default);
@@ -490,8 +495,8 @@ NetconfAgent::subscribeToNotifications(const CfgServersMapPair& service_pair) {
490495
optional<DataNode> const notification_tree,
491496
NotificationTimeStamp const timestamp) {
492497
NetconfAgentCallback agent(service_pair);
493-
return agent.event_notif(session, subscription_id, notification_type, notification_tree,
494-
timestamp);
498+
return agent.eventNotif(session, subscription_id, notification_type, notification_tree,
499+
timestamp);
495500
};
496501
try {
497502
auto exception_handler = [model](std::exception& ex) {

src/bin/netconf/netconf_messages.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const char* values[] = {
6767
"NETCONF_MODULE_REVISION_ERR", "Essential module %1 does NOT have the right revision: expected %2, got %3",
6868
"NETCONF_MODULE_REVISION_WARN", "Module %1 does NOT have the right revision: expected %2, got %3",
6969
"NETCONF_NOTIFICATION_INTERNAL_ERROR", "an internal error occurred while sending an event notification for module %1: %2",
70-
"NETCONF_NOTIFICATION_RECEIVED", "Received notification of type %1 for module %1: %2",
70+
"NETCONF_NOTIFICATION_RECEIVED", "Received notification of type %1 for module %2: '%3'",
7171
"NETCONF_NOT_SUBSCRIBED_TO_NOTIFICATIONS", "subscribing to notifications for %1 server with %2 module failed: %3",
7272
"NETCONF_RUN_EXIT", "application is exiting the event loop",
7373
"NETCONF_SET_CONFIG", "set configuration to %1 server: %2",

src/bin/netconf/netconf_messages.mes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ The error message indicates that kea-netconf got an error while sysrepo was send
8585
This error is not fatal and can be recovered from.
8686
The name of the module and the internal error message are printed.
8787

88-
% NETCONF_NOTIFICATION_RECEIVED Received notification of type %1 for module %1: %2
88+
% NETCONF_NOTIFICATION_RECEIVED Received notification of type %1 for module %2: '%3'
8989
This informational message logs any YANG notification that has been signaled
9090
by the server, sent to kea-netconf which then was forwarded to subscribed
9191
clients. To achieve this, kea-netconf subscribes itself as a client to all

0 commit comments

Comments
 (0)