Skip to content

host_topology: usage of strncat might overflow buffer #57

@devreal

Description

@devreal

GCC issues the following warning for the function dart__base__host_topology__module_locations:

In function ‘strncat’,
    inlined from ‘dart__base__host_topology__module_locations’ at /home/joseph/src/dash/dash/dart-impl/base/src/internal/host_topology.c:103:13:
/usr/include/x86_64-linux-gnu/bits/string3.h:156:10: warning: call to __builtin___strncat_chk might overflow destination buffer
   return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));

The way strncat is used here is dangerous since the size parameter does not describe the size of the destination buffer. The man page reads:

The strncat() function is similar, except that
* it will use at most n bytes from src; [...]

A safe way would be to use snprintf or the like to control the amount of data written and thus to avoid memory corruption.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions