Better error checking on session metadata
authorBert Vermeulen <bert@biot.com>
Sun, 17 Nov 2013 23:03:53 +0000 (00:03 +0100)
committerBert Vermeulen <bert@biot.com>
Sun, 17 Nov 2013 23:03:53 +0000 (00:03 +0100)
session.c

index 109ede10516251c8079d40ce67575532013867f4..7eeab16b839a4b6ab3a275b5dc0fda5aa26915d4 100644 (file)
--- a/session.c
+++ b/session.c
@@ -170,10 +170,27 @@ SRD_API int srd_session_metadata_set(struct srd_session *sess, int key,
                return SRD_ERR_ARG;
        }
 
+       if (!key) {
+               srd_err("Invalid key.");
+               return SRD_ERR_ARG;
+       }
+
+       if (!data) {
+               srd_err("Invalid value.");
+               return SRD_ERR_ARG;
+       }
+
+       /* Hardcoded to samplerate/uint64 for now. */
+
        if (key != SRD_CONF_SAMPLERATE) {
                srd_err("Unknown config key %d.", key);
                return SRD_ERR_ARG;
        }
+       if (!g_variant_is_of_type(data, G_VARIANT_TYPE_UINT64)) {
+               srd_err("Invalid value type: expected uint64, got %s",
+                               g_variant_get_type_string(data));
+               return SRD_ERR_ARG;
+       }
 
        srd_dbg("Setting session %d samplerate to %"PRIu64".",
                        sess->session_id, g_variant_get_uint64(data));