You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
module() calls RootNode() which expects the Node interface type. (*yang.Module)(nil) is passed into RootNode().
ParentNode() is called with (*yang.Module)(nil). This is not n == nil because the interface has a nil pointer value (same explanation as this). This results in a nil pointer dereference panic.
RootNode() is vulnerable to panics due to a non-nil interface (e.g., when a nil *yang.Module is passed). Even if we properly nil check in RootNode() with reflection, we will again be vulnerable to a panic again with Kind() in node.go:160.
The root cause here is that module() is called with (*yang.Module)(nil). We should nil check FindModuleByPrefix() before calling module() to prevent the panic.
The text was updated successfully, but these errors were encountered:
sengleung
added a commit
to sengleung/goyang
that referenced
this issue
Oct 23, 2023
Previously, if FindModuleByPrefix() returns nil in Find(), it would
continue to call module() with nil, resulting in a nil pointer
dereference panic when trying to call ParentNode() from RootNode().
The fix is to return an error if FindModuleByPrefix() returns nil.
Fixesopenconfig#251
Previously, if FindModuleByPrefix() returns nil in Find(), it would
continue to call module() with nil, resulting in a nil pointer
dereference panic when trying to call ParentNode() from RootNode().
The fix is to return an error if FindModuleByPrefix() returns nil.
Fixes#251
Panic stack trace of goyang source files:
goyang/pkg/yang/entry.go
Line 1325 in 944052f
Find()
callsFindModuleByPrefix()
which returns nil of type*yang.Module
.module()
is called with(*yang.Module)(nil)
.goyang/pkg/yang/node.go
Lines 158 to 160 in 944052f
goyang/pkg/yang/node.go
Lines 146 to 147 in 944052f
goyang/pkg/yang/yang.go
Line 142 in 944052f
module()
callsRootNode()
which expects theNode
interface type.(*yang.Module)(nil)
is passed intoRootNode()
.ParentNode()
is called with(*yang.Module)(nil)
. This is notn == nil
because the interface has a nil pointer value (same explanation as this). This results in a nil pointer dereference panic.RootNode()
is vulnerable to panics due to a non-nil interface (e.g., when a nil*yang.Module
is passed). Even if we properly nil check inRootNode()
with reflection, we will again be vulnerable to a panic again withKind()
in node.go:160.The root cause here is that
module()
is called with(*yang.Module)(nil)
. We should nil checkFindModuleByPrefix()
before callingmodule()
to prevent the panic.The text was updated successfully, but these errors were encountered: