diff mbox

[API-NEXT,4/5] linux-gen: classification: fix creating cos with no name

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

Commit Message

Elo, Matias (Nokia - FI/Espoo) Oct. 14, 2016, 8:49 a.m. UTC
Previously trying to create a class-of-service 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_classification.c                   | 11 ++++++++---
 .../validation/api/classification/odp_classification_basic.c  |  4 +---
 2 files changed, 9 insertions(+), 6 deletions(-)

-- 
2.7.4
diff mbox

Patch

diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c
index ea223bf..5d7125b 100644
--- a/platform/linux-generic/odp_classification.c
+++ b/platform/linux-generic/odp_classification.c
@@ -178,9 +178,14 @@  odp_cos_t odp_cls_cos_create(const char *name, odp_cls_cos_param_t *param)
 	for (i = 0; i < ODP_COS_MAX_ENTRY; i++) {
 		LOCK(&cos_tbl->cos_entry[i].s.lock);
 		if (0 == cos_tbl->cos_entry[i].s.valid) {
-			strncpy(cos_tbl->cos_entry[i].s.name, name,
-				ODP_COS_NAME_LEN - 1);
-			cos_tbl->cos_entry[i].s.name[ODP_COS_NAME_LEN - 1] = 0;
+			char *cos_name = cos_tbl->cos_entry[i].s.name;
+
+			if (name == NULL) {
+				cos_name[0] = 0;
+			} else {
+				strncpy(cos_name, name, ODP_COS_NAME_LEN - 1);
+				cos_name[ODP_COS_NAME_LEN - 1] = 0;
+			}
 			for (j = 0; j < ODP_PMR_PER_COS_MAX; j++) {
 				cos_tbl->cos_entry[i].s.pmr[j] = NULL;
 				cos_tbl->cos_entry[i].s.linked_cos[j] = NULL;
diff --git a/test/common_plat/validation/api/classification/odp_classification_basic.c b/test/common_plat/validation/api/classification/odp_classification_basic.c
index 372377d..9817287 100644
--- a/test/common_plat/validation/api/classification/odp_classification_basic.c
+++ b/test/common_plat/validation/api/classification/odp_classification_basic.c
@@ -16,7 +16,6 @@  void classification_test_create_cos(void)
 	odp_cls_cos_param_t cls_param;
 	odp_pool_t pool;
 	odp_queue_t queue;
-	char cosname[ODP_COS_NAME_LEN];
 
 	pool = pool_create("cls_basic_pool");
 	CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);
@@ -24,13 +23,12 @@  void classification_test_create_cos(void)
 	queue = queue_create("cls_basic_queue", true);
 	CU_ASSERT_FATAL(queue != ODP_QUEUE_INVALID);
 
-	sprintf(cosname, "ClassOfService");
 	odp_cls_cos_param_init(&cls_param);
 	cls_param.pool = pool;
 	cls_param.queue = queue;
 	cls_param.drop_policy = ODP_COS_DROP_POOL;
 
-	cos = odp_cls_cos_create(cosname, &cls_param);
+	cos = odp_cls_cos_create(NULL, &cls_param);
 	CU_ASSERT(odp_cos_to_u64(cos) != odp_cos_to_u64(ODP_COS_INVALID));
 	odp_cos_destroy(cos);
 	odp_pool_destroy(pool);