Commit 0fa7cbba authored by Jaco Hofmann's avatar Jaco Hofmann
Browse files

Fix dangerous strncpy, closes #61

parent cfdba059
Pipeline #1252 passed with stages
in 128 minutes and 48 seconds
...@@ -19,14 +19,14 @@ struct platform_ctx { ...@@ -19,14 +19,14 @@ struct platform_ctx {
}; };
static static
int get_tlkm_version(platform_ctx_t *ctx, char *v) int get_tlkm_version(platform_ctx_t *ctx, char *v, int v_buffer_length)
{ {
struct tlkm_ioctl_version_cmd c = { .version = "", }; struct tlkm_ioctl_version_cmd c = { .version = "", };
if (ioctl(ctx->fd_tlkm, TLKM_IOCTL_VERSION, &c)) { if (ioctl(ctx->fd_tlkm, TLKM_IOCTL_VERSION, &c)) {
ERR("getting version from device driver failed: %s (%d)", strerror(errno), errno); ERR("getting version from device driver failed: %s (%d)", strerror(errno), errno);
return errno; return errno;
} }
strncpy(v, c.version, strlen(c.version) + 1); strncpy(v, c.version, v_buffer_length);
return 0; return 0;
} }
...@@ -71,7 +71,7 @@ platform_res_t init_platform(platform_ctx_t *ctx) ...@@ -71,7 +71,7 @@ platform_res_t init_platform(platform_ctx_t *ctx)
r = PERR_TLKM_ERROR; r = PERR_TLKM_ERROR;
goto err_tlkm; goto err_tlkm;
} }
if (get_tlkm_version(ctx, ctx->version)) goto err_ioctl; if (get_tlkm_version(ctx, ctx->version, TLKM_VERSION_SZ)) goto err_ioctl;
LOG(LPLL_TLKM, "TLKM version: %s", ctx->version); LOG(LPLL_TLKM, "TLKM version: %s", ctx->version);
if (enum_devs(ctx)) goto err_ioctl; if (enum_devs(ctx)) goto err_ioctl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment