Fix ASAN build error 37/234537/2
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 27 May 2020 06:03:30 +0000 (15:03 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 27 May 2020 06:11:24 +0000 (15:11 +0900)
- Build error is caused by -Werror=stringop-truncation option

Change-Id: Ia869d851825d02920b8b835e2a54419b04b77f04
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
containers/mkv/matroska_reader.c
containers/rtsp/rtsp_reader.c
host_applications/linux/apps/raspicam/RaspiCamControl.c
host_applications/linux/apps/raspicam/RaspiStill.c
interface/vcos/pthreads/vcos_pthreads.c
interface/vmcs_host/vc_vchi_filesys.c
interface/vmcs_host/vcilcs_out.c

index 8625d0c..df91e8b 100755 (executable)
@@ -352,7 +352,7 @@ typedef struct VC_CONTAINER_TRACK_MODULE_T
    int64_t  timecode_scale;
    uint32_t duration;
    int64_t  frame_duration;
-   char codecid[MKV_CODECID_MAX];
+   char codecid[MKV_MAX_STRING_SIZE + 2];
 
    union {
       /* video specific */
@@ -1320,7 +1320,7 @@ static VC_CONTAINER_STATUS_T mkv_read_subelements_track_entry( VC_CONTAINER_T *p
       LOG_FORMAT(p_ctx, "%s", stringbuf);
 
       if(id == MKV_ELEMENT_ID_TRACK_CODEC_ID)
-         strncpy(track_module->codecid, stringbuf, MKV_CODECID_MAX-1);
+         strncpy(track_module->codecid, stringbuf, MKV_MAX_STRING_SIZE + 1);
 
       return VC_CONTAINER_SUCCESS;
    }
index 2d96234..5df4d25 100755 (executable)
@@ -1052,12 +1052,9 @@ static VC_CONTAINER_STATUS_T rtsp_merge_uris( VC_CONTAINER_T *p_ctx,
    if (vc_uri_scheme(relative_uri) != NULL)
    {
       /* URI is absolute, not relative, so return it as the merged URI */
-      size_t len = strlen(relative_uri_str);
-
-      *p_merged_uri_str = (char *)malloc(len + 1);
+      *p_merged_uri_str = strdup(relative_uri_str);
       if (!*p_merged_uri_str) goto tidy_up;
 
-      strncpy(*p_merged_uri_str, relative_uri_str, len);
       status = VC_CONTAINER_SUCCESS;
       goto tidy_up;
    }
@@ -1112,15 +1109,12 @@ static VC_CONTAINER_STATUS_T rtsp_parse_control_attribute( VC_CONTAINER_T *p_ctx
 
    if (!*attribute || strcmp(attribute, "*") == 0)
    {
-      size_t len = strlen(base_uri_str);
-
-      *p_control_uri_str = (char *)malloc(len + 1);
+      *p_control_uri_str = strdup(base_uri_str);
       if (!*p_control_uri_str)
       {
          LOG_ERROR(p_ctx, "RTSP: Failed to allocate control URI");
          return VC_CONTAINER_ERROR_OUT_OF_MEMORY;
       }
-      strncpy(*p_control_uri_str, base_uri_str, len);
    } else {
       status = rtsp_merge_uris(p_ctx, base_uri_str, attribute, p_control_uri_str);
    }
@@ -1245,7 +1239,7 @@ static VC_CONTAINER_STATUS_T rtsp_open_file_reader( VC_CONTAINER_T *p_ctx,
       goto tidy_up;
    }
 
-   strncpy(new_path, rtsp_path, len);
+   strncpy(new_path, rtsp_path, len + 1);
    extension = strrchr(new_path, '.');          /* Find extension, to replace it */
    if (!extension)
       extension = new_path + strlen(new_path);  /* No extension, so append instead */
index a700010..e46128d 100755 (executable)
@@ -1615,7 +1615,7 @@ int raspicamcontrol_set_annotate(MMAL_COMPONENT_T *camera, const int settings, c
             strftime(annotate.text, MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V3, string, &tm );
             process_datetime = 0;
          }else{
-            strncpy(annotate.text, string, MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V3);
+            strncpy(annotate.text, string, MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V3 - 1);
          }
          annotate.text[MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V3-1] = '\0';
       }
@@ -1627,7 +1627,7 @@ int raspicamcontrol_set_annotate(MMAL_COMPONENT_T *camera, const int settings, c
          }else{
             strftime(tmp, 32, "%X", &tm );
          }
-         strncat(annotate.text, tmp, MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V3 - strlen(annotate.text) - 1);
+         strncat(annotate.text, tmp, MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V3 - strlen(annotate.text));
       }
 
       if (process_datetime && (settings & ANNOTATE_DATE_TEXT))
@@ -1637,7 +1637,7 @@ int raspicamcontrol_set_annotate(MMAL_COMPONENT_T *camera, const int settings, c
          }else{
             strftime(tmp, 32, "%x", &tm );
          }
-         strncat(annotate.text, tmp, MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V3 - strlen(annotate.text) - 1);
+         strncat(annotate.text, tmp, MMAL_CAMERA_ANNOTATE_MAX_TEXT_LEN_V3 - strlen(annotate.text));
       }
 
       if (settings & ANNOTATE_SHUTTER_SETTINGS)
index 0c3cf3f..d791200 100755 (executable)
@@ -294,7 +294,7 @@ static void set_sensor_defaults(RASPISTILL_STATE *state)
                state->width = param.cameras[state->cameraNum].max_width;
             if (state->height == 0)
                state->height = param.cameras[state->cameraNum].max_height;
-            strncpy(state->camera_name,  param.cameras[state->cameraNum].camera_name, MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN);
+            strncpy(state->camera_name,  param.cameras[state->cameraNum].camera_name, MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN - 1);
             state->camera_name[MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN-1] = 0;
          }
          else
index 77ce58c..3295f7a 100755 (executable)
@@ -205,7 +205,7 @@ VCOS_STATUS_T vcos_thread_create(VCOS_THREAD_T *thread,
    thread->arg = arg;
    thread->legacy = local_attrs->legacy;
 
-   strncpy(thread->name, name, sizeof(thread->name));
+   strncpy(thread->name, name, sizeof(thread->name) - 1);
    thread->name[sizeof(thread->name)-1] = '\0';
    memset(thread->at_exit, 0, sizeof(thread->at_exit));
 
index 26a34b9..29c94db 100755 (executable)
@@ -373,8 +373,8 @@ static int vc_filesys_single_string(uint32_t param, const char *str, uint32_t fn
    {
       vc_filesys_client.fileserv_msg.params[0] = param;
       /* coverity[buffer_size_warning] - the length of str has already been checked */
-      strncpy((char*)vc_filesys_client.fileserv_msg.data, str, FILESERV_MAX_DATA);
-    
+      strncpy((char*)vc_filesys_client.fileserv_msg.data, str, FILESERV_MAX_DATA - 1);
+
       if (vchi_msg_stub(&vc_filesys_client.fileserv_msg, fn, len+1+16) == FILESERV_RESP_OK)
       {
          if(return_param)
index 545ddc7..f5d3c11 100755 (executable)
@@ -689,7 +689,7 @@ static OMX_ERRORTYPE vcil_out_GetExtensionIndex(OMX_IN  OMX_HANDLETYPE hComponen
    comp = (VC_PRIVATE_COMPONENT_T *) pComp->pComponentPrivate;
 
    exe.reference = comp->reference;
-   strncpy(exe.name, cParameterName, 128);
+   strncpy(exe.name, cParameterName, 128 - 1);
    exe.name[127] = 0;
 
    if(ilcs_execute_function(st->ilcs, IL_GET_EXTENSION_INDEX, &exe, sizeof(exe), &resp, &rlen) < 0 || rlen != sizeof(resp))