platform: merge branch 'th/platform-recvmsgs-fixes-bgo761959'

https://bugzilla.gnome.org/show_bug.cgi?id=761959
This commit is contained in:
Thomas Haller
2016-02-16 14:14:58 +01:00
3 changed files with 24 additions and 28 deletions

View File

@@ -41,6 +41,8 @@
/* always include these headers for our internal source files. */
#include <stdlib.h>
#include "nm-glib.h"
#include "nm-version.h"
#include "gsystem-local-alloc.h"

View File

@@ -22,7 +22,15 @@
#ifndef __NM_MACROS_INTERNAL_H__
#define __NM_MACROS_INTERNAL_H__
#include "nm-default.h"
/********************************************************/
/**
* nm_auto_free:
*
* Call free() on a variable location when it goes out of scope.
*/
#define nm_auto_free __attribute__ ((cleanup(_nm_auto_free_impl)))
GS_DEFINE_CLEANUP_FUNCTION(void*, _nm_auto_free_impl, free)
/********************************************************/

View File

@@ -5556,8 +5556,7 @@ event_handler_recvmsgs (NMPlatform *platform, gboolean handle_events)
{
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
struct nl_sock *sk = priv->nlh;
int n, err = 0, multipart = 0, interrupted = 0, nrecv = 0;
unsigned char *buf = NULL;
int n, err = 0, multipart = 0, interrupted = 0;
struct nlmsghdr *hdr;
WaitForNlResponseResult seq_result;
@@ -5567,10 +5566,12 @@ event_handler_recvmsgs (NMPlatform *platform, gboolean handle_events)
initialize the variable. Thomas Graf.
*/
struct sockaddr_nl nla = {0};
struct nl_msg *msg = NULL;
struct ucred *creds = NULL;
nm_auto_free struct ucred *creds = NULL;
nm_auto_free unsigned char *buf = NULL;
continue_reading:
g_clear_pointer (&buf, free);
g_clear_pointer (&creds, free);
errno = 0;
n = nl_recv (sk, &nla, &buf, &creds);
@@ -5600,9 +5601,9 @@ continue_reading:
hdr = (struct nlmsghdr *) buf;
while (nlmsg_ok (hdr, n)) {
nm_auto_nlmsg struct nl_msg *msg = NULL;
gboolean abort_parsing = FALSE;
nlmsg_free (msg);
msg = nlmsg_convert (hdr);
if (!msg) {
err = -NLE_NOMEM;
@@ -5611,13 +5612,13 @@ continue_reading:
nlmsg_set_proto (msg, NETLINK_ROUTE);
nlmsg_set_src (msg, &nla);
nrecv++;
if (!creds || creds->pid) {
if (creds)
_LOGD ("netlink: recvmsg: received non-kernel message (pid %d)", creds->pid);
_LOGT ("netlink: recvmsg: received non-kernel message (pid %d)", creds->pid);
else
_LOGD ("netlink: recvmsg: received message without credentials");
_LOGT ("netlink: recvmsg: received message without credentials");
err = 0;
goto stop;
}
@@ -5697,19 +5698,13 @@ continue_reading:
}
event_seq_check (platform, msg, seq_result);
err = 0;
hdr = nlmsg_next (hdr, &n);
if (abort_parsing)
goto out;
}
goto stop;
nlmsg_free (msg);
free (buf);
free (creds);
buf = NULL;
msg = NULL;
creds = NULL;
err = 0;
hdr = nlmsg_next (hdr, &n);
}
if (multipart) {
/* Multipart message not yet complete, continue reading */
@@ -5722,18 +5717,9 @@ stop:
* Repeat reading. */
goto continue_reading;
}
err = 0;
out:
nlmsg_free (msg);
free (buf);
free (creds);
if (interrupted)
err = -NLE_DUMP_INTR;
if (!err)
err = nrecv;
return err;
}