libdvr: LGE Coverity aml dvr report [1/1]

PD#TV-61227

Problem:
LGE report Coverity errors of libdvr.

Solution:
Fix BUFFER_SIZE errors reported by Coverity.

Verify:
Locally tested OK in AH212 RDK environment.

Signed-off-by: Wentao.MA <wentao.ma@amlogic.com>
Change-Id: Ic15f8dee504e940a1a5a183d4e50f85438e7b0c1
diff --git a/src/dvr_wrapper.c b/src/dvr_wrapper.c
index 7d7f25c..0fb942f 100644
--- a/src/dvr_wrapper.c
+++ b/src/dvr_wrapper.c
@@ -849,7 +849,12 @@
   p_seg->seg_info = *seg_info;
   /*generate the segment info used in playback*/
   p_seg->playback_info.segment_id = p_seg->seg_info.id;
-  strncpy(p_seg->playback_info.location, ctx->playback.param_open.location, sizeof(p_seg->playback_info.location));
+  const int len = strlen(ctx->playback.param_open.location);
+  if (len >= DVR_MAX_LOCATION_SIZE || len <= 0) {
+    DVR_WRAPPER_ERROR("Invalid playback.param_open.location length %d", len);
+    return DVR_FAILURE;
+  }
+  strncpy(p_seg->playback_info.location, ctx->playback.param_open.location, len+1);
   p_seg->playback_info.pids = *p_pids;
   p_seg->playback_info.flags = flags;
   list_add(&p_seg->head, &ctx->segments);
@@ -1179,7 +1184,13 @@
 
   start_param = &ctx->record.param_start;
   memset(start_param, 0, sizeof(*start_param));
-  strncpy(start_param->location, ctx->record.param_open.location, sizeof(start_param->location));
+  const int len = strlen(ctx->record.param_open.location);
+  if (len >= DVR_MAX_LOCATION_SIZE || len <= 0) {
+    DVR_WRAPPER_ERROR("Invalid record.param_open.location length %d",len);
+    pthread_mutex_unlock(&ctx->wrapper_lock);
+    return DVR_FAILURE;
+  }
+  strncpy(start_param->location, ctx->record.param_open.location, len+1);
   start_param->segment.segment_id = ctx->record.next_segment_id++;
   start_param->segment.nb_pids = params->pids_info.nb_pids;
   for (i = 0; i < params->pids_info.nb_pids; i++) {
@@ -1391,7 +1402,13 @@
   }
 
   memset(start_param, 0, sizeof(*start_param));
-  strncpy(start_param->location, ctx->record.param_open.location, sizeof(start_param->location));
+  const int len = strlen(ctx->record.param_open.location);
+  if (len >= DVR_MAX_LOCATION_SIZE || len <= 0) {
+    DVR_WRAPPER_ERROR("Invalid record.param_open.location length %d",len);
+    pthread_mutex_unlock(&ctx->wrapper_lock);
+    return DVR_FAILURE;
+  }
+  strncpy(start_param->location, ctx->record.param_open.location, len+1);
   start_param->segment.segment_id = ctx->record.next_segment_id++;
   start_param->segment.nb_pids = params->nb_pids;
   for (i = 0; i < params->nb_pids; i++) {