summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Dritschler <timo.dritschler@kit.edu>2015-01-21 16:12:28 +0100
committerTimo Dritschler <timo.dritschler@kit.edu>2015-01-21 16:12:28 +0100
commitcac103dc4d9016cb07a2da991b3338a01a753b30 (patch)
treecf87e6e2d9d790e9327284806c23ccac662c9be7
parent3cceb501d225b314a4f3188c32bd630cf306cd00 (diff)
downloadkiro-cac103dc4d9016cb07a2da991b3338a01a753b30.tar.gz
kiro-cac103dc4d9016cb07a2da991b3338a01a753b30.tar.bz2
kiro-cac103dc4d9016cb07a2da991b3338a01a753b30.tar.xz
kiro-cac103dc4d9016cb07a2da991b3338a01a753b30.zip
Fixed a bug in KiroClient when connection fails during setup
Added early-out functionality to all KIRO interfaces to prevent segfaults when passing a NULL pointer
-rw-r--r--CMakeLists.txt4
-rw-r--r--src/kiro-client.c17
-rw-r--r--src/kiro-server.c12
-rw-r--r--src/kiro-trb.c21
4 files changed, 38 insertions, 16 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cad6854..a5db2aa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,8 +26,8 @@ else()
endif()
find_package(PkgConfig)
-pkg_check_modules(GLIB2 glib-2.0>=2.24 REQUIRED)
-pkg_check_modules(GOBJECT2 gobject-2.0>=2.24 REQUIRED)
+pkg_check_modules(GLIB2 glib-2.0>=2.32 REQUIRED)
+pkg_check_modules(GOBJECT2 gobject-2.0>=2.32 REQUIRED)
include_directories(
SYSTEM
diff --git a/src/kiro-client.c b/src/kiro-client.c
index 6e140b5..6d0d3f5 100644
--- a/src/kiro-client.c
+++ b/src/kiro-client.c
@@ -80,8 +80,7 @@ kiro_client_new (void)
void
kiro_client_free (KiroClient *client)
{
- if (!client)
- return;
+ g_return_if_fail (client != NULL);
if (KIRO_IS_CLIENT (client))
g_object_unref (client);
@@ -93,6 +92,7 @@ kiro_client_free (KiroClient *client)
static void
kiro_client_init (KiroClient *self)
{
+ g_return_if_fail (self != NULL);
KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
memset (priv, 0, sizeof (&priv));
//Hack to make the 'unused function' from the kiro-rdma include go away...
@@ -105,6 +105,7 @@ kiro_client_init (KiroClient *self)
static void
kiro_client_finalize (GObject *object)
{
+ g_return_if_fail (object != NULL);
if (KIRO_IS_CLIENT (object))
kiro_client_disconnect ((KiroClient *)object);
G_OBJECT_CLASS (kiro_client_parent_class)->finalize (object);
@@ -114,6 +115,7 @@ kiro_client_finalize (GObject *object)
static void
kiro_client_class_init (KiroClientClass *klass)
{
+ g_return_if_fail (klass != NULL);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = kiro_client_finalize;
g_type_class_add_private (klass, sizeof (KiroClientPrivate));
@@ -246,6 +248,7 @@ start_client_main_loop (gpointer data)
int
kiro_client_connect (KiroClient *self, const char *address, const char *port)
{
+ g_return_val_if_fail (self != NULL, -1);
KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
if (priv->conn) {
@@ -285,7 +288,7 @@ kiro_client_connect (KiroClient *self, const char *address, const char *port)
}
g_debug ("Route to server resolved");
- struct kiro_connection_context *ctx = (struct kiro_connection_context *)g_try_malloc (sizeof (struct kiro_connection_context));
+ struct kiro_connection_context *ctx = (struct kiro_connection_context *)g_try_malloc0 (sizeof (struct kiro_connection_context));
if (!ctx) {
g_critical ("Failed to create connection context (Out of memory?)");
@@ -350,6 +353,7 @@ fail:
int
kiro_client_sync (KiroClient *self)
{
+ g_return_val_if_fail (self != NULL, -1);
KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
if (!priv->conn) {
@@ -418,6 +422,8 @@ done:
gint
kiro_client_ping_server (KiroClient *self)
{
+ g_return_val_if_fail (self != NULL, -1);
+
// Will be returned. -1 for error.
gint t_usec = 0;
@@ -501,6 +507,7 @@ end:
void *
kiro_client_get_memory (KiroClient *self)
{
+ g_return_val_if_fail (self != NULL, NULL);
KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
if (!priv->conn)
@@ -518,6 +525,7 @@ kiro_client_get_memory (KiroClient *self)
size_t
kiro_client_get_memory_size (KiroClient *self)
{
+ g_return_val_if_fail (self != NULL, 0);
KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
if (!priv->conn)
@@ -535,8 +543,7 @@ kiro_client_get_memory_size (KiroClient *self)
void
kiro_client_disconnect (KiroClient *self)
{
- if (!self)
- return;
+ g_return_if_fail (self != NULL);
KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
diff --git a/src/kiro-server.c b/src/kiro-server.c
index ff6c0f8..fadc329 100644
--- a/src/kiro-server.c
+++ b/src/kiro-server.c
@@ -86,9 +86,7 @@ kiro_server_new (void)
void
kiro_server_free (KiroServer *server)
{
- if (!server)
- return;
-
+ g_return_if_fail (server != NULL);
if (KIRO_IS_SERVER (server))
g_object_unref (server);
else
@@ -99,6 +97,7 @@ kiro_server_free (KiroServer *server)
static void
kiro_server_init (KiroServer *self)
{
+ g_return_if_fail (self != NULL);
KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE (self);
memset (priv, 0, sizeof (&priv));
}
@@ -107,6 +106,7 @@ kiro_server_init (KiroServer *self)
static void
kiro_server_finalize (GObject *object)
{
+ g_return_if_fail (object != NULL);
KiroServer *self = KIRO_SERVER (object);
//Clean up the server
kiro_server_stop (self);
@@ -118,6 +118,7 @@ kiro_server_finalize (GObject *object)
static void
kiro_server_class_init (KiroServerClass *klass)
{
+ g_return_if_fail (klass != NULL);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = kiro_server_finalize;
g_type_class_add_private (klass, sizeof (KiroServerPrivate));
@@ -406,6 +407,7 @@ start_server_main_loop (gpointer data)
int
kiro_server_start (KiroServer *self, const char *address, const char *port, void *mem, size_t mem_size)
{
+ g_return_val_if_fail (self != NULL, -1);
KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE (self);
if (priv->base) {
@@ -530,9 +532,7 @@ disconnect_client (gpointer data, gpointer user_data)
void
kiro_server_stop (KiroServer *self)
{
- if (!self)
- return;
-
+ g_return_if_fail (self != NULL);
KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE (self);
if (!priv->base)
diff --git a/src/kiro-trb.c b/src/kiro-trb.c
index 585e8e3..6a4a080 100644
--- a/src/kiro-trb.c
+++ b/src/kiro-trb.c
@@ -73,9 +73,7 @@ kiro_trb_new (void)
void
kiro_trb_free (KiroTrb *trb)
{
- if (!trb)
- return;
-
+ g_return_if_fail (trb != NULL);
if (KIRO_IS_TRB (trb))
g_object_unref (trb);
else
@@ -86,6 +84,7 @@ kiro_trb_free (KiroTrb *trb)
static
void kiro_trb_init (KiroTrb *self)
{
+ g_return_if_fail (self != NULL);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
priv->initialized = 0;
}
@@ -94,6 +93,7 @@ void kiro_trb_init (KiroTrb *self)
static void
kiro_trb_finalize (GObject *object)
{
+ g_return_if_fail (object != NULL);
KiroTrb *self = KIRO_TRB (object);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
@@ -107,6 +107,7 @@ kiro_trb_finalize (GObject *object)
static void
kiro_trb_class_init (KiroTrbClass *klass)
{
+ g_return_if_fail (klass != NULL);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = kiro_trb_finalize;
g_type_class_add_private (klass, sizeof (KiroTrbPrivate));
@@ -135,6 +136,7 @@ write_header (KiroTrbPrivate *priv)
uint64_t
kiro_trb_get_element_size (KiroTrb *self)
{
+ g_return_val_if_fail (self != NULL, 0);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
if (priv->initialized != 1)
@@ -147,6 +149,7 @@ kiro_trb_get_element_size (KiroTrb *self)
uint64_t
kiro_trb_get_max_elements (KiroTrb *self)
{
+ g_return_val_if_fail (self != NULL, 0);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
if (priv->initialized != 1)
@@ -159,6 +162,7 @@ kiro_trb_get_max_elements (KiroTrb *self)
uint64_t
kiro_trb_get_raw_size (KiroTrb *self)
{
+ g_return_val_if_fail (self != NULL, 0);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
if (priv->initialized != 1)
@@ -171,6 +175,7 @@ kiro_trb_get_raw_size (KiroTrb *self)
void *
kiro_trb_get_raw_buffer (KiroTrb *self)
{
+ g_return_val_if_fail (self != NULL, NULL);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
if (priv->initialized != 1)
@@ -184,6 +189,7 @@ kiro_trb_get_raw_buffer (KiroTrb *self)
void *
kiro_trb_get_element (KiroTrb *self, uint64_t element)
{
+ g_return_val_if_fail (self != NULL, NULL);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
if (priv->initialized != 1)
@@ -203,6 +209,7 @@ kiro_trb_get_element (KiroTrb *self, uint64_t element)
void
kiro_trb_flush (KiroTrb *self)
{
+ g_return_if_fail (self != NULL);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
priv->iteration = 0;
priv->current = priv->frame_top;
@@ -213,6 +220,7 @@ kiro_trb_flush (KiroTrb *self)
void
kiro_trb_purge (KiroTrb *self, gboolean free_memory)
{
+ g_return_if_fail (self != NULL);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
priv->iteration = 0;
priv->current = NULL;
@@ -232,6 +240,7 @@ kiro_trb_purge (KiroTrb *self, gboolean free_memory)
int
kiro_trb_is_setup (KiroTrb *self)
{
+ g_return_val_if_fail (self != NULL, 0);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
return priv->initialized;
}
@@ -240,6 +249,7 @@ kiro_trb_is_setup (KiroTrb *self)
int
kiro_trb_reshape (KiroTrb *self, uint64_t element_size, uint64_t element_count)
{
+ g_return_val_if_fail (self != NULL, -1);
if (element_size < 1 || element_count < 1)
return -1;
@@ -260,6 +270,7 @@ kiro_trb_reshape (KiroTrb *self, uint64_t element_size, uint64_t element_count)
int
kiro_trb_push (KiroTrb *self, void *element_in)
{
+ g_return_val_if_fail (self != NULL, -1);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
if (priv->initialized != 1)
@@ -284,6 +295,7 @@ kiro_trb_push (KiroTrb *self, void *element_in)
void *
kiro_trb_dma_push (KiroTrb *self)
{
+ g_return_val_if_fail (self != NULL, NULL);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
if (priv->initialized != 1)
@@ -308,6 +320,7 @@ kiro_trb_dma_push (KiroTrb *self)
void
kiro_trb_refresh (KiroTrb *self)
{
+ g_return_if_fail (self != NULL);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
if (priv->initialized != 1)
@@ -327,6 +340,7 @@ kiro_trb_refresh (KiroTrb *self)
void
kiro_trb_adopt (KiroTrb *self, void *buff_in)
{
+ g_return_if_fail (self != NULL);
if (!buff_in)
return;
@@ -344,6 +358,7 @@ kiro_trb_adopt (KiroTrb *self, void *buff_in)
int
kiro_trb_clone (KiroTrb *self, void *buff_in)
{
+ g_return_val_if_fail (self != NULL, -1);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
struct KiroTrbInfo *header = (struct KiroTrbInfo *)buff_in;
void *newmem = g_try_malloc0 (header->buffer_size_bytes);