Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect expressions reported by Coverity #2035

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/OVAL/probes/SEAP/generic/strto.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int64_t strto_int64 (const char *str, size_t len, char **endptr, int base)
{
int errno_copy = 0;
int64_t result = 0;
char *null_str = calloc(len + 1, sizeof(str));
char *null_str = calloc(len + 1, sizeof(*str));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be easier and more redable to just use malloc() here than using sizeof on a const char.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use malloc, but I think, in this case, we should also call memset so the string would be null terminated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense


memcpy(null_str, str, len);
errno = 0;
Expand All @@ -90,7 +90,7 @@ uint64_t strto_uint64 (const char *str, size_t len, char **endptr, int base)
{
int errno_copy = 0;
int64_t result = 0;
char *null_str = calloc(len + 1, sizeof(str));
char *null_str = calloc(len + 1, sizeof(*str));

memcpy(null_str, str, len);
errno = 0;
Expand All @@ -106,7 +106,7 @@ double strto_double (const char *str, size_t len, char **endptr)
{
int errno_copy = 0;
int64_t result = 0;
char *null_str = calloc(len + 1, sizeof(str));
char *null_str = calloc(len + 1, sizeof(*str));

memcpy(null_str, str, len);
errno = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/OVAL/probes/independent/sql57_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ int sql57_probe_main(probe_ctx *ctx, void *arg)
err = dbSQL_eval(engine, version, conn, sqlexp, ctx);
__exit:
if (engine != NULL) {
__clearmem(conn, strlen(engine));
__clearmem(engine, strlen(engine));
free(engine);
}

Expand Down
2 changes: 1 addition & 1 deletion src/OVAL/probes/independent/sql_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ int sql_probe_main(probe_ctx *ctx, void *arg)
err = dbSQL_eval(engine, version, conn, sqlexp, ctx);
__exit:
if (engine != NULL) {
__clearmem(conn, strlen(engine));
__clearmem(engine, strlen(engine));
free(engine);
}

Expand Down