Skip to content

Commit

Permalink
Changes as per review
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubhamturakhia committed Apr 21, 2021
1 parent fa94cc3 commit 525ee45
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions aws_protocol_adaptor/device_client/aws_nvmsgbroker.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,12 @@ bool is_valid_connection_str(char *connection_str)
return true;
}

char *generate_sha256_hash(char *str, char *output_str)
char *generate_sha256_hash(char *output_str, char *str)
{
unsigned char hashval[SHA256_DIGEST_LENGTH];
int len = SHA256_DIGEST_LENGTH * 2 + 1;
char res[len];
strcpy(res, output_str);

This comment has been minimized.

Copy link
@lummish

lummish Apr 21, 2021

@Shubhamturakhia Explain to me what you're trying to do here.

This comment has been minimized.

Copy link
@Shubhamturakhia

Shubhamturakhia Apr 21, 2021

Author

As the problem of res returned gets invalidated after the function call, according to the ways you explained the 1st one was to provide output_str as argument and this is currently empty and gets copied to res and after the hash code is returned back to the msgapi function the complete process gets completed and successful to return the hash code.

This comment has been minimized.

Copy link
@lummish

lummish Apr 22, 2021

@Shubhamturakhia Are you aware of how the strcpy function works, though? It simply copies the contents of source (in this case, output_str) into destination (in this case, res). This does nothing to solve the problem of the contents of res being invalidated after it is returned.

You should be storing the hash string in output_str, not res.

SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, str, strlen(str));
Expand All @@ -419,7 +420,8 @@ char *generate_sha256_hash(char *str, char *output_str)

NvDsMsgApiErrorType nvds_msgapi_connection_signature(char *broker_str, char *cfg, char *output_str, int max_len)
{
strcpy(output_str, ""); // Initializing output_str as empty string if successful which is updated later by SHA-256 hash else empty string is returned
// Value of output_str must be empty string if operation is unsuccessful
strcpy(output_str, "");
int required_output_str_len = 2 * SHA256_DIGEST_LENGTH + 1
if (broker_str == NULL || cfg == NULL)
{
Expand All @@ -435,6 +437,6 @@ NvDsMsgApiErrorType nvds_msgapi_connection_signature(char *broker_str, char *cfg
{
return NVDS_MSGAPI_ERR;
}
output_str = generate_sha256_hash(broker_str, output_str);
output_str = generate_sha256_hash(output_str, broker_str);
return NVDS_MSGAPI_OK;
}

0 comments on commit 525ee45

Please sign in to comment.