diff options
author | Felix Abecassis <felix.abecassis@gmail.com> | 2019-06-21 11:25:08 +0300 |
---|---|---|
committer | Sylvain Jeaugey <sjeaugey@nvidia.com> | 2019-06-21 11:25:08 +0300 |
commit | 37e4f8729e5e6604ab739b2353064139af43fe2d (patch) | |
tree | a59b0cd337f7c027626922fa1fd8acb342c23c2d | |
parent | 6d8b2421bc087f142a1edfb5f60a53040a5eac82 (diff) |
Fix out-of-bounds read in ncclStrToCpuset (#233)
The affinityStr string was not null-terminated but was passed to strlen(3).
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
-rw-r--r-- | src/init.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/init.cc b/src/init.cc index 80af287..66a4865 100644 --- a/src/init.cc +++ b/src/init.cc @@ -879,10 +879,12 @@ static ncclResult_t getCpuGpuAffinity(int cudaDev, cpu_set_t* mask) { path[PATH_MAX-1] = '\0'; int fd; SYSCHECKVAL(open(path, O_RDONLY), "open", fd); - char affinityStr[sizeof(cpu_set_t)*2]; + char affinityStr[sizeof(cpu_set_t)*2 + 1]; int r = read(fd, affinityStr, sizeof(cpu_set_t)*2); - if (r > 0) + if (r > 0) { + affinityStr[r] = '\0'; NCCLCHECK(ncclStrToCpuset(affinityStr, mask)); + } close(fd); free(cudaPath); return ncclSuccess; |