Skip to content

Commit

Permalink
block-crypto: Fix off-by-one in keypath
Browse files Browse the repository at this point in the history
  Commit 6ffa1d8 replaced the use
  of strncpy with safe_strncpy.  When we calculate the length here,
  we calculate it up to the separator, but don't include the sep.
  When the string is passed to safe_strncpy, that function subtracts an
  extra 1 byte to make room for the null character, which ends up
  cutting off the last character in the path since the length was
  exact, and relied on the 0-initialized, statically allocated buffer
  to null terminate the string by default.

  This commit increases the length value by one before calling
  safe_strncpy to avoid losing the last byte of data. This essentially
  copies the path, including the separator which was omitted before,
  and then replaces the separator with a null character.

Signed-off-by: Chris Rogers <[email protected]>
  • Loading branch information
Chris Rogers committed Feb 12, 2024
1 parent 26019a2 commit fd6bbfe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/block-crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ find_keyfile(char **keyfile, const char *dirs,
safe_strncpy(keydir, dirs, sizeof(keydir));
dirs = NULL;
} else {
size_t len = sep - dirs;
size_t len = (sep - dirs) + 1;
safe_strncpy(keydir, dirs, len);
dirs = sep+1;
}
Expand Down

0 comments on commit fd6bbfe

Please sign in to comment.