Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Commit d5d9730

Browse files
chivakkerseanvk
authored andcommitted
wrapper_openDriver: fix string management logic
string copies and cats should be done on a clean array so that we don't have garbage when changing parts of the string The libraries are subject to be opened within the Sandbox when using ChromiumOS, so this dlopen calls should just return the handle to the already opened library. Using a bad string will result in an error and the sandbox is locked so no open of any library is possible. Also it is responsibility of the caller of dlopen to call dlclose as calling dlclose will cause the sandbox to avoid any future open of the library in case of error Change-Id: I417335f057fb0332beb6598ef2f6ff2a446deb0a Signed-off-by: Daniel Charles <daniel.charles@intel.com>
1 parent 2356b85 commit d5d9730

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/wrapper_drv_video.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,24 @@ static VAStatus vawr_openDriver(VADriverContextP ctx, char *driver_name)
7474
char *driver_dir = "/usr/lib64/va/drivers/";
7575
void *handle = NULL;
7676

77-
char *driver_path = (char *) malloc( strlen(driver_dir) +
77+
char *driver_path = (char *) calloc(1, strlen(driver_dir) +
7878
strlen(driver_name) +
79-
strlen(DRIVER_EXTENSION) + 2 );
79+
strlen(DRIVER_EXTENSION) + 1 );
8080
if (!driver_path) {
8181
vawr_errorMessage("%s L%d Out of memory!n",
8282
__FUNCTION__, __LINE__);
8383
return VA_STATUS_ERROR_ALLOCATION_FAILED;
8484
}
8585

86-
strncpy( driver_path, driver_dir, strlen(driver_dir) + 1);
87-
strncat( driver_path, "/", strlen("/") );
86+
strncpy( driver_path, driver_dir, strlen(driver_dir) );
8887
strncat( driver_path, driver_name, strlen(driver_name) );
8988
strncat( driver_path, DRIVER_EXTENSION, strlen(DRIVER_EXTENSION) );
9089

9190
handle = dlopen( driver_path, RTLD_NOW| RTLD_GLOBAL);
9291
if (!handle) {
93-
/* Don't give errors for non-existing files */
94-
if (0 == access( driver_path, F_OK))
95-
vawr_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
92+
/* Manage error if the file exists or not we need to know what's going
93+
* on */
94+
vawr_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
9695
} else {
9796
VADriverInit init_func = NULL;
9897
char init_func_s[256];
@@ -123,19 +122,18 @@ static VAStatus vawr_openDriver(VADriverContextP ctx, char *driver_name)
123122
if (compatible_versions[i].major < 0) {
124123
vawr_errorMessage("%s has no function %s\n",
125124
driver_path, init_func_s);
126-
dlclose(handle);
127125
} else {
128126
if (init_func)
129127
vaStatus = (*init_func)(ctx);
130128
if (VA_STATUS_SUCCESS != vaStatus) {
131129
vawr_errorMessage("%s init failed\n", driver_path);
132-
dlclose(handle);
133130
} else {
134131
/* TODO: Store the handle to a private structure */
135132
}
136133
}
137134
}
138135
free(driver_path);
136+
driver_path=NULL;
139137
return vaStatus;
140138
}
141139

0 commit comments

Comments
 (0)