Skip to content

Commit

Permalink
fixed safe usage of strlen
Browse files Browse the repository at this point in the history
  • Loading branch information
pasco1995 committed Nov 18, 2024
1 parent a2c2387 commit dcb2e83
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions core/src/mender-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,23 @@ mender_utils_keystore_get_item_index(mender_keystore_t *keystore, char *name) {

/* Find item index */
int index = 0;
if (NULL != keystore) {
if ((NULL != keystore) && (NULL != name)) {
while ((NULL != keystore[index].name) && (NULL != keystore[index].value)) {
/* Compare name string length */
if (strlen(keystore[index].name) != strlen(name)) {
index++;
continue;
}
/* Compare name strings */
if (0 != strncmp(keystore[index].name, name, strlen(name))) {
index++;
continue;

if (NULL != keystore[index].name) {
/* Compare name string length */
if (strlen(keystore[index].name) != strlen(name)) {
index++;
continue;
}

/* Compare name strings */
if (0 != strncmp(keystore[index].name, name, strlen(name))) {
index++;
continue;
}
return index;
}
return index;
}
}

Expand Down

0 comments on commit dcb2e83

Please sign in to comment.