Instead of a fixed size shared library path that could in theory
get truncated when concatenating, use a dynamically allocated buffer
via asprintf.

Signed-off-by: Stephen Hemminger <[email protected]>
---
 lib/eal/common/eal_common_options.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/lib/eal/common/eal_common_options.c 
b/lib/eal/common/eal_common_options.c
index b1fb670ea0..6aa078e135 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -570,7 +570,6 @@ static int
 eal_plugindir_init(const char *path)
 {
        struct dirent *dent = NULL;
-       char sopath[PATH_MAX];
        DIR *d = NULL;
 
        if (path == NULL || *path == '\0')
@@ -584,19 +583,29 @@ eal_plugindir_init(const char *path)
        }
 
        while ((dent = readdir(d)) != NULL) {
+               char *sopath = NULL;
                struct stat sb;
 
                if (!ends_with(dent->d_name, ".so") && !ends_with(dent->d_name, 
".so."ABI_VERSION))
                        continue;
 
-               snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
+               if (asprintf(&sopath, "%s/%s", path, dent->d_name) < 0) {
+                       EAL_LOG(ERR, "failed to create full path %s/%s",
+                               path, dent->d_name);
+                       continue;
+               }
 
                /* if a regular file, add to list to load */
-               if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
+               if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode))) {
+                       free(sopath);
                        continue;
+               }
 
-               if (eal_plugin_add(sopath) == -1)
+               if (eal_plugin_add(sopath) == -1) {
+                       free(sopath);
                        break;
+               }
+               free(sopath);
        }
 
        closedir(d);
-- 
2.51.0

Reply via email to