From aa6d4d08d4c161aa91ba2ef4330e03b61a0ca3cb Mon Sep 17 00:00:00 2001 From: dmitry pervushin Date: Mon, 11 May 2020 19:31:25 +0200 Subject: strncpy: it should depend on size of 1st argument There is no point to depend on strlen of second argument, otherwise it could be a simple strcpy. Instead, let's make it depending on sizeof(destination) ...and make sure that result is NUL-terminated, too Bug 2973859 Change-Id: Ifc941fab07e503b7b980696950d65b8bb10bf4ff Signed-off-by: dmitry pervushin Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2342281 Tested-by: mobile promotions Reviewed-by: automaticguardword Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Phoenix Jung Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/common/mm/vm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/nvgpu/common/mm/vm.c b/drivers/gpu/nvgpu/common/mm/vm.c index 4a7cc828..e6ca38c8 100644 --- a/drivers/gpu/nvgpu/common/mm/vm.c +++ b/drivers/gpu/nvgpu/common/mm/vm.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2020, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -339,7 +339,8 @@ int __nvgpu_vm_init(struct mm_gk20a *mm, #endif /* Initialize the page table data structures. */ - strncpy(vm->name, name, min(strlen(name), sizeof(vm->name))); + strncpy(vm->name, name, sizeof(vm->name)); + vm->name[sizeof(vm->name) - 1] = '\0'; err = nvgpu_gmmu_init_page_table(vm); if (err) { goto clean_up_vgpu_vm; -- cgit v1.2.2