Skip to content

Commit

Permalink
Merge pull request allinurl#2120 from cgzones/cov
Browse files Browse the repository at this point in the history
Coverity Scan
  • Loading branch information
allinurl authored May 25, 2021
2 parents 90c282b + b25fe14 commit 0e8cd7c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
29 changes: 16 additions & 13 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,20 +582,17 @@ extract_tls_version_cipher (char *tkn, char **cipher, char **tls_version) {
code = strtoull (tkn, &bEnd, 10);
if (tkn == bEnd || *bEnd != '\0' || errno == ERANGE) {
LOG_DEBUG (("unable to convert cipher code to a valid decimal."));
free (tkn);
return 1;
goto fail;
}

/* ssl context */
if (!(ctx = SSL_CTX_new (SSLv23_server_method ()))) {
LOG_DEBUG (("Unable to create a new SSL_CTX_new to extact TLS."));
free (tkn);
return 1;
goto fail;
}
if (!(ssl = SSL_new (ctx))) {
LOG_DEBUG (("Unable to create a new instace of SSL_new to extact TLS."));
free (tkn);
return 1;
goto fail;
}

code_be = htobe16 (code);
Expand All @@ -604,14 +601,12 @@ extract_tls_version_cipher (char *tkn, char **cipher, char **tls_version) {

if (!(c = SSL_CIPHER_find (ssl, cipherid))) {
LOG_DEBUG (("Unable to find cipher to extact TLS."));
free (tkn);
return 1;
goto fail;
}

if (!(sn = SSL_CIPHER_standard_name (c))) {
LOG_DEBUG (("Unable to get cipher standard name to extact TLS."));
free (tkn);
return 1;
goto fail;
}
*cipher = xstrdup (sn);
*tls_version = xstrdup (SSL_CIPHER_get_version (c));
Expand All @@ -621,6 +616,14 @@ extract_tls_version_cipher (char *tkn, char **cipher, char **tls_version) {
SSL_CTX_free (ctx);

return 0;

fail:
free (tkn);
if (ssl)
SSL_free (ssl);
if (ctx)
SSL_CTX_free (ctx);
return 1;
}
#endif

Expand Down Expand Up @@ -1362,15 +1365,15 @@ parse_format (GLogItem * logitem, char *str, char *lfmt) {
return 0;

if (tilde && *p != '\0') {
if ((str == NULL) || (*str == '\0'))
if (*str == '\0')
return 0;
if (special_specifier (logitem, &str, &p) == 1)
return 1;
tilde = 0;
}
/* %h */
else if (perc && *p != '\0') {
if ((str == NULL) || (*str == '\0'))
if (*str == '\0')
return 0;

memset (end, 0, sizeof end);
Expand Down Expand Up @@ -1822,7 +1825,7 @@ fgetline (FILE * fp) {
while (1) {
if (!fgets (buf, sizeof (buf), fp)) {
if (conf.process_and_exit && errno == EAGAIN) {
nanosleep ((const struct timespec[]) { {0, 100000000L} }, NULL);
(void) nanosleep ((const struct timespec[]) { {0, 100000000L} }, NULL);
continue;
} else
break;
Expand Down
6 changes: 4 additions & 2 deletions src/persistence.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,18 @@ migrate_unique_key (char *key) {

nkey = xstrdup ("");
while ((ptr = strchr (key, '|'))) {
if (!(token = extract_by_delim (&key, "|")))
if (!(token = extract_by_delim (&key, "|"))) {
free (nkey);
return NULL;
}

append_str (&nkey, token);
append_str (&nkey, "|");
free (token);
key++;
delims++;
}
if (key && delims == 2) {
if (delims == 2) {
sprintf (agent_hex, "%" PRIx32, djb2 ((unsigned char *) key));
append_str (&nkey, agent_hex);
}
Expand Down
11 changes: 8 additions & 3 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,17 +520,22 @@ int
str_to_time (const char *str, const char *fmt, struct tm *tm) {
char *end = NULL, *sEnd = NULL;
unsigned long long ts = 0;
int us = strcmp ("%f", fmt) == 0;
int ms = strcmp ("%*", fmt) == 0;
int us, ms;
#if !defined(__GLIBC__)
int se = strcmp ("%s", fmt) == 0;
int se;
#endif

time_t seconds = 0;

if (str == NULL || *str == '\0' || fmt == NULL || *fmt == '\0')
return 1;

us = strcmp ("%f", fmt) == 0;
ms = strcmp ("%*", fmt) == 0;
#if !defined(__GLIBC__)
se = strcmp ("%s", fmt) == 0;
#endif

/* check if char string needs to be converted from milli/micro seconds */
/* note that MUSL doesn't have %s under strptime(3) */
#if !defined(__GLIBC__)
Expand Down

0 comments on commit 0e8cd7c

Please sign in to comment.