diff mbox

[API-NEXT,3/5] linux-gen: queue: fix creating queue with no name

Message ID 1476434952-8282-4-git-send-email-matias.elo@nokia.com
State Accepted
Commit ac563d15b95d884764ffa2f48eedce6f5b408fca
Headers show

Commit Message

Elo, Matias (Nokia - FI/Espoo) Oct. 14, 2016, 8:49 a.m. UTC
Previously trying to create a queue with no name (=NULL) caused a
segfault. Fix this and test it in the validation suite.

Signed-off-by: Matias Elo <matias.elo@nokia.com>

---
 platform/linux-generic/odp_queue.c            |  8 ++++++--
 test/common_plat/validation/api/queue/queue.c | 10 +++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

-- 
2.7.4
diff mbox

Patch

diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c
index bec1e51..7af2515 100644
--- a/platform/linux-generic/odp_queue.c
+++ b/platform/linux-generic/odp_queue.c
@@ -86,8 +86,12 @@  queue_entry_t *get_qentry(uint32_t queue_id)
 static int queue_init(queue_entry_t *queue, const char *name,
 		      const odp_queue_param_t *param)
 {
-	strncpy(queue->s.name, name, ODP_QUEUE_NAME_LEN - 1);
-
+	if (name == NULL) {
+		queue->s.name[0] = 0;
+	} else {
+		strncpy(queue->s.name, name, ODP_QUEUE_NAME_LEN - 1);
+		queue->s.name[ODP_QUEUE_NAME_LEN - 1] = 0;
+	}
 	memcpy(&queue->s.param, param, sizeof(odp_queue_param_t));
 	if (queue->s.param.sched.lock_count >
 	    SCHEDULE_ORDERED_LOCKS_PER_QUEUE)
diff --git a/test/common_plat/validation/api/queue/queue.c b/test/common_plat/validation/api/queue/queue.c
index dc3a977..1f7913a 100644
--- a/test/common_plat/validation/api/queue/queue.c
+++ b/test/common_plat/validation/api/queue/queue.c
@@ -137,7 +137,7 @@  void queue_test_mode(void)
 
 void queue_test_param(void)
 {
-	odp_queue_t queue;
+	odp_queue_t queue, null_queue;
 	odp_event_t enev[MAX_BUFFER_QUEUE];
 	odp_event_t deev[MAX_BUFFER_QUEUE];
 	odp_buffer_t buf;
@@ -173,6 +173,11 @@  void queue_test_param(void)
 	CU_ASSERT(&queue_context == odp_queue_context(queue));
 	CU_ASSERT(odp_queue_destroy(queue) == 0);
 
+	/* Create queue with no name */
+	odp_queue_param_init(&qparams);
+	null_queue = odp_queue_create(NULL, &qparams);
+	CU_ASSERT(ODP_QUEUE_INVALID != null_queue);
+
 	/* Plain type queue */
 	odp_queue_param_init(&qparams);
 	qparams.type        = ODP_QUEUE_TYPE_PLAIN;
@@ -185,6 +190,9 @@  void queue_test_param(void)
 	CU_ASSERT(ODP_QUEUE_TYPE_PLAIN == odp_queue_type(queue));
 	CU_ASSERT(&queue_context == odp_queue_context(queue));
 
+	/* Destroy queue with no name */
+	CU_ASSERT(odp_queue_destroy(null_queue) == 0);
+
 	msg_pool = odp_pool_lookup("msg_pool");
 	buf = odp_buffer_alloc(msg_pool);
 	CU_ASSERT_FATAL(buf != ODP_BUFFER_INVALID);