Skip to content

Commit

Permalink
erts: Fix memory corruption when reading topology info
Browse files Browse the repository at this point in the history
If the number of processors actually found while reading sysfs
is lower than the configured value, we realloc() the cpuinfo array
to the smaller size, but we then iterate it using the original
configured size, thus corrupting memory beyond the allocated
block.
  • Loading branch information
sverker committed Mar 15, 2012
1 parent 7484721 commit 8c34a2d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions erts/lib_src/common/erl_misc_utils.c
Expand Up @@ -727,7 +727,7 @@ adjust_processor_nodes(erts_cpu_info_t *cpuinfo, int no_nodes)

prev = NULL;
this = &cpuinfo->topology[0];
last = &cpuinfo->topology[cpuinfo->configured-1];
last = &cpuinfo->topology[cpuinfo->topology_size-1];
while (1) {
if (processor == this->processor) {
if (node != this->node)
Expand Down Expand Up @@ -939,7 +939,7 @@ read_topology(erts_cpu_info_t *cpuinfo)

if (res > 1) {
prev = this++;
last = &cpuinfo->topology[cpuinfo->configured-1];
last = &cpuinfo->topology[cpuinfo->topology_size-1];

while (1) {
this->thread = ((this->node == prev->node
Expand Down Expand Up @@ -1094,7 +1094,7 @@ read_topology(erts_cpu_info_t *cpuinfo)

if (res > 1) {
prev = this++;
last = &cpuinfo->topology[cpuinfo->configured-1];
last = &cpuinfo->topology[cpuinfo->topology_size-1];

while (1) {
this->thread = ((this->node == prev->node
Expand Down

0 comments on commit 8c34a2d

Please sign in to comment.