Skip to content

Commit

Permalink
libopaeuio: fix issues identified by checkers (#138)
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Whisonant <tim.whisonant@intel.com>
  • Loading branch information
tswhison committed Mar 10, 2021
1 parent a2d2d9c commit 1d9192a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion libopaeuio/opaeuio.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
fprintf(stderr, "%s:%u:%s() **ERROR** [%s] : " format , \
__SHORT_FILE__, __LINE__, __func__, strerror(errno), ##__VA_ARGS__)

// dfl_dev.xxx
#define MAX_DFL_DEVICE 11

STATIC int opae_uio_read_sysfs_uint64(const char *path, uint64_t *puint)
{
FILE *fp;
Expand Down Expand Up @@ -246,7 +249,7 @@ STATIC int opae_uio_init(struct opae_uio *u, const char *dfl_device)
glob_t globbuf;
int res = 0;
size_t len;
char *p;
char *p = NULL;
const char *glob_fmts[] = {
"/sys/bus/dfl/devices/%s/uio/uio*",
"/sys/bus/dfl/devices/%s/uio_pdrv_genirq.*.auto/uio/uio*",
Expand All @@ -257,6 +260,8 @@ STATIC int opae_uio_init(struct opae_uio *u, const char *dfl_device)
memset(u, 0, sizeof(*u));
u->device_fd = -1;

memset(&globbuf, 0, sizeof(globbuf));

// Use glob to discover the uio device name.
for (i = 0 ; glob_fmts[i] ; ++i) {
int glob_res;
Expand Down Expand Up @@ -345,6 +350,12 @@ int opae_uio_open(struct opae_uio *u, const char *dfl_device)
return 1;
}

if (strlen(dfl_device) > MAX_DFL_DEVICE) {
ERR("%s is too long to be a DFL device name.\n",
dfl_device);
return 2;
}

return opae_uio_init(u, dfl_device);
}

Expand Down

0 comments on commit 1d9192a

Please sign in to comment.