Skip to content

Commit b15cd54

Browse files
author
David Sommerseth
committed
Added some extra error checks with libnl calls
Signed-off-by: David Sommerseth <davids@redhat.com>
1 parent e52b663 commit b15cd54

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

python-ethtool/etherinfo.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ int get_etherinfo_link(PyEtherInfo *self)
185185
return 0;
186186
}
187187
link = rtnl_link_alloc();
188-
/* FIXME: Error handling? */
188+
if( !link ) {
189+
return 0;
190+
}
189191
rtnl_link_set_ifindex(link, self->index);
190192
nl_cache_foreach_filter(link_cache, OBJ_CAST(link), callback_nl_link, self);
191193
rtnl_link_put(link);
@@ -236,7 +238,9 @@ PyObject * get_etherinfo_address(PyEtherInfo *self, nlQuery query)
236238
return NULL;
237239
}
238240
addr = rtnl_addr_alloc();
239-
/* FIXME: Error handling? */
241+
if( !addr ) {
242+
return NULL;
243+
}
240244
rtnl_addr_set_ifindex(addr, self->index);
241245

242246
switch( query ) {

python-ethtool/netlink.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ int open_netlink(PyEtherInfo *ethi)
5757

5858
/* No earlier connections exists, establish a new one */
5959
nlconnection = nl_socket_alloc();
60-
nl_connect(nlconnection, NETLINK_ROUTE);
61-
if( (nlconnection != NULL) ) {
60+
if( nlconnection != NULL ) {
61+
nl_connect(nlconnection, NETLINK_ROUTE);
6262
/* Force O_CLOEXEC flag on the NETLINK socket */
6363
if( fcntl(nl_socket_get_fd(nlconnection), F_SETFD, FD_CLOEXEC) == -1 ) {
6464
fprintf(stderr,

0 commit comments

Comments
 (0)