Skip to content

Commit

Permalink
a possible fix for TAINTED_SCALAR coverity issues
Browse files Browse the repository at this point in the history
Signed-off-by: Mahdi Varasteh <varasteh@amnesh.ir>
  • Loading branch information
m-varasteh committed Sep 20, 2023
1 parent 7a80a23 commit 4194777
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions ospfd/ospf_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ static int ospf_auth_check_md5_digest(struct ospf_interface *oi,
unsigned char digest[OSPF_AUTH_MD5_SIZE];
struct ospf_neighbor *nbr;
struct crypt_key *ck = NULL;
uint16_t length = ntohs(ospfh->length);
unsigned int length = ntohs(ospfh->length);

assert(length <= UINT32_MAX); /* for coverity's sake */

if (key == NULL) {
ck = ospf_crypt_key_lookup(OSPF_IF_PARAM(oi, auth_crypt),
Expand Down Expand Up @@ -222,22 +224,21 @@ static int ospf_auth_check_md5_digest(struct ospf_interface *oi,
static int ospf_auth_make_md5_digest(struct ospf_interface *oi,
struct ospf_packet *op, struct key *key)
{
void *ibuf;
struct ospf_header *ospfh;
void *ibuf = STREAM_DATA(op->s);
struct ospf_header *ospfh = (struct ospf_header *)ibuf;
unsigned char digest[OSPF_AUTH_MD5_SIZE];
uint16_t length;
unsigned int length = ntohs(ospfh->length);
#ifdef CRYPTO_OPENSSL
EVP_MD_CTX *ctx;
#elif CRYPTO_INTERNAL
MD5_CTX ctx;
#endif
char auth_key[OSPF_AUTH_MD5_SIZE + 1];

assert(length <= UINT32_MAX); /* for coverity's sake */

memset(auth_key, 0, OSPF_AUTH_MD5_SIZE + 1);
strlcpy(auth_key, key->string, OSPF_AUTH_MD5_SIZE + 1);
ibuf = STREAM_DATA(op->s);
ospfh = (struct ospf_header *)ibuf;
length = ntohs(ospfh->length);
/* Generate a digest for the ospf packet - their digest + our digest. */
#ifdef CRYPTO_OPENSSL
unsigned int md5_size = OSPF_AUTH_MD5_SIZE;
Expand Down

0 comments on commit 4194777

Please sign in to comment.