1
1

Merge pull request #6489 from markalle/v4.0.x

v4.0.x: opal_hwloc_base_cset2str() off-by-1 in its strncat()
Этот коммит содержится в:
Howard Pritchard 2019-03-14 17:00:42 -06:00 коммит произвёл GitHub
родитель b5a81afe54 fcf53becc3
Коммит 27c0e95b01
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23

Просмотреть файл

@ -18,6 +18,8 @@
* and Technology (RIST). All rights reserved. * and Technology (RIST). All rights reserved.
* Copyright (C) 2018 Mellanox Technologies, Ltd. * Copyright (C) 2018 Mellanox Technologies, Ltd.
* All rights reserved. * All rights reserved.
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
* Copyright (c) 2019 IBM Corporation. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -1721,14 +1723,14 @@ int opal_hwloc_base_cset2str(char *str, int len,
for (core_index = 0; core_index < num_cores; ++core_index) { for (core_index = 0; core_index < num_cores; ++core_index) {
if (map[socket_index][core_index] > 0) { if (map[socket_index][core_index] > 0) {
if (!first) { if (!first) {
strncat(str, ", ", len - strlen(str)); strncat(str, ", ", len - strlen(str) - 1);
} }
first = false; first = false;
snprintf(tmp, stmp, "socket %d[core %d[hwt %s]]", snprintf(tmp, stmp, "socket %d[core %d[hwt %s]]",
socket_index, core_index, socket_index, core_index,
bitmap2rangestr(map[socket_index][core_index])); bitmap2rangestr(map[socket_index][core_index]));
strncat(str, tmp, len - strlen(str)); strncat(str, tmp, len - strlen(str) - 1);
} }
} }
} }
@ -1784,7 +1786,7 @@ int opal_hwloc_base_cset2mapstr(char *str, int len,
for (socket = hwloc_get_obj_by_type(topo, HWLOC_OBJ_SOCKET, 0); for (socket = hwloc_get_obj_by_type(topo, HWLOC_OBJ_SOCKET, 0);
NULL != socket; NULL != socket;
socket = socket->next_cousin) { socket = socket->next_cousin) {
strncat(str, "[", len - strlen(str)); strncat(str, "[", len - strlen(str) - 1);
/* Iterate over all existing cores in this socket */ /* Iterate over all existing cores in this socket */
core_index = 0; core_index = 0;
@ -1796,7 +1798,7 @@ int opal_hwloc_base_cset2mapstr(char *str, int len,
socket->cpuset, socket->cpuset,
HWLOC_OBJ_CORE, ++core_index)) { HWLOC_OBJ_CORE, ++core_index)) {
if (core_index > 0) { if (core_index > 0) {
strncat(str, "/", len - strlen(str)); strncat(str, "/", len - strlen(str) - 1);
} }
/* Iterate over all existing PUs in this core */ /* Iterate over all existing PUs in this core */
@ -1811,13 +1813,13 @@ int opal_hwloc_base_cset2mapstr(char *str, int len,
/* Is this PU in the cpuset? */ /* Is this PU in the cpuset? */
if (hwloc_bitmap_isset(cpuset, pu->os_index)) { if (hwloc_bitmap_isset(cpuset, pu->os_index)) {
strncat(str, "B", len - strlen(str)); strncat(str, "B", len - strlen(str) - 1);
} else { } else {
strncat(str, ".", len - strlen(str)); strncat(str, ".", len - strlen(str) - 1);
} }
} }
} }
strncat(str, "]", len - strlen(str)); strncat(str, "]", len - strlen(str) - 1);
} }
return OPAL_SUCCESS; return OPAL_SUCCESS;