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 <dpervushin@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2342281
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: automaticguardword <automaticguardword@nvidia.com>
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Phoenix Jung <pjung@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
GVS: Gerrit_Virtual_Submit
This commit is contained in:
dmitry pervushin
2020-05-11 19:31:25 +02:00
committed by mobile promotions
parent 9d1e07ca18
commit aa6d4d08d4

View File

@@ -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;