misc: tegra-profiler: fix coverity defects
Igor Nabirushkin [Sun, 5 Jun 2016 12:58:52 +0000 (16:58 +0400)]
Fix coverity defects. Use strlcpy() instead of strcpy() and
snprintf() instead of sprintf().

Coverity ID 24003 24004 24005 24006

Bug 200192567

Change-Id: Ifd33023ea9cf622e0376bcd249d5f0c4da28abfa
Signed-off-by: Igor Nabirushkin <inabirushkin@nvidia.com>
Reviewed-on: http://git-master/r/1171557
(cherry picked from commit 503371a9301b85f92b395497199a082754ed2b48)
Reviewed-on: http://git-master/r/1249594
(cherry picked from commit d054a43aca021ea757ed1428269ffd402be7526f)

drivers/misc/tegra-profiler/auth.c
drivers/misc/tegra-profiler/comm.c
drivers/misc/tegra-profiler/hrt.c
drivers/misc/tegra-profiler/mmap.c

index e324584..dc6d10d 100644 (file)
@@ -129,7 +129,8 @@ auth_read(struct file *filp,
        ((u32 *)buf)[2] = QUADD_SECURITY_REQUEST_CMD_TEST_DEBUG_FLAG;
        ((u32 *)buf)[3] = strlen(data->package_name);
 
-       strcpy(buf + 4 * sizeof(u32), data->package_name);
+       strlcpy(buf + 4 * sizeof(u32), data->package_name,
+               QUADD_MAX_PACKAGE_NAME);
        msg_length = strlen(data->package_name) + 4 * sizeof(u32);
 
        mutex_unlock(&auth_ctx.lock);
index e90982d..89637b8 100644 (file)
@@ -607,8 +607,10 @@ device_ioctl(struct file *file,
        case IOCTL_GET_VERSION:
                memset(&versions, 0, sizeof(versions));
 
-               strcpy((char *)versions.branch, QUADD_MODULE_BRANCH);
-               strcpy((char *)versions.version, QUADD_MODULE_VERSION);
+               strlcpy((char *)versions.branch, QUADD_MODULE_BRANCH,
+                       sizeof(versions.branch));
+               strlcpy((char *)versions.version, QUADD_MODULE_VERSION,
+                       sizeof(versions.version));
 
                versions.samples_version = QUADD_SAMPLES_VERSION;
                versions.io_version = QUADD_IO_VERSION;
index 08190c4..da7f197 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * drivers/misc/tegra-profiler/hrt.c
  *
- * Copyright (c) 2016, NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (c) 2015-2016, NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -759,9 +759,9 @@ void quadd_hrt_stop(void)
 {
        struct quadd_ctx *ctx = hrt.quadd_ctx;
 
-       pr_info("Stop hrt, samples all/skipped: %llu/%llu\n",
-               atomic64_read(&hrt.counter_samples),
-               atomic64_read(&hrt.skipped_samples));
+       pr_info("Stop hrt, samples all/skipped: %lld/%lld\n",
+               (long long)atomic64_read(&hrt.counter_samples),
+               (long long)atomic64_read(&hrt.skipped_samples));
 
        if (ctx->pl310)
                ctx->pl310->stop();
index 2347047..22c74ff 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * drivers/misc/tegra-profiler/mmap.c
  *
- * Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.
+ * Copyright (c) 2015-2016, NVIDIA CORPORATION.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms and conditions of the GNU General Public License,
@@ -28,6 +28,8 @@
 #include "comm.h"
 #include "hrt.h"
 
+#define TMP_BUFFER_SIZE        (PATH_MAX + sizeof(u64))
+
 static void
 put_mmap_sample(struct quadd_mmap_data *s, char *filename,
                size_t length, unsigned long pgoff, int is_file_exists)
@@ -76,7 +78,7 @@ void quadd_process_mmap(struct vm_area_struct *vma, pid_t pid)
        if (!(vma->vm_flags & VM_EXEC))
                return;
 
-       tmp_buf = kzalloc(PATH_MAX + sizeof(u64), GFP_ATOMIC);
+       tmp_buf = kzalloc(TMP_BUFFER_SIZE, GFP_ATOMIC);
        if (!tmp_buf)
                return;
 
@@ -109,10 +111,10 @@ void quadd_process_mmap(struct vm_area_struct *vma, pid_t pid)
                }
 
                if (name)
-                       strcpy(tmp_buf, name);
+                       strlcpy(tmp_buf, name, TMP_BUFFER_SIZE);
                else
-                       sprintf(tmp_buf, "[vma:%08lx-%08lx]",
-                               vma->vm_start, vma->vm_end);
+                       snprintf(tmp_buf, TMP_BUFFER_SIZE, "[vma:%08lx-%08lx]",
+                                vma->vm_start, vma->vm_end);
 
                file_name = tmp_buf;
                length = strlen(file_name) + 1;
@@ -164,7 +166,7 @@ int quadd_get_current_mmap(pid_t pid)
 
        pr_info("Get mapped memory objects\n");
 
-       tmp_buf = kzalloc(PATH_MAX + sizeof(u64), GFP_ATOMIC);
+       tmp_buf = kzalloc(TMP_BUFFER_SIZE, GFP_ATOMIC);
        if (!tmp_buf)
                return -ENOMEM;
 
@@ -201,10 +203,11 @@ int quadd_get_current_mmap(pid_t pid)
                        }
 
                        if (name)
-                               strcpy(tmp_buf, name);
+                               strlcpy(tmp_buf, name, TMP_BUFFER_SIZE);
                        else
-                               sprintf(tmp_buf, "[vma:%08lx-%08lx]",
-                                       vma->vm_start, vma->vm_end);
+                               snprintf(tmp_buf, TMP_BUFFER_SIZE,
+                                        "[vma:%08lx-%08lx]",
+                                        vma->vm_start, vma->vm_end);
 
                        file_name = tmp_buf;
                        length = strlen(file_name) + 1;