[RFC,7/8] eal: add check for sysfs path overflow
Checks
Commit Message
It shouldn't happen but in theory sysfs socket could overflow.
Add a check for it.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/eal/linux/eal_hugepage_info.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
@@ -150,8 +150,12 @@ get_num_hugepages_on_node(const char *subdir, unsigned int socket, size_t sz)
return 0;
}
- snprintf(path, sizeof(path), "%s/%s/%s",
+ if (snprintf(path, sizeof(path), "%s/%s/%s", socketpath, subdir, nr_hp_file) >= PATH_MAX) {
+ EAL_LOG(NOTICE, "Socket path %s/%s/%s is truncated",
socketpath, subdir, nr_hp_file);
+ return 0;
+ }
+
if (eal_parse_sysfs_value(path, &num_pages) < 0)
return 0;