Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strcpy of two char #847

Closed
mhoemmen opened this issue Sep 27, 2022 · 0 comments · Fixed by #848
Closed

strcpy of two char #847

mhoemmen opened this issue Sep 27, 2022 · 0 comments · Fixed by #848

Comments

@mhoemmen
Copy link
Contributor

mhoemmen commented Sep 27, 2022

There are a few parts of the SVD function that do strcpy(&dst, &src), where each of dst and src is a char. For example:

strcpy(&jobu, &new_u);

This is incorrect for several reasons.

  1. strcpy will attempt to read past the bounds of src in order to look for a null terminator (\0 character). Just doing that is UB.
  2. If strcpy is lucky enough to find a null terminator, it will write both src and the null terminator (thus, two characters) to &dst. This is UB because dst only points to one character. It could clobber something on the stack (maybe even src).
  3. There's no guarantee that the next character after src is a null terminator. This means strcpy could clobber arbitrarily many bytes on the stack with random other bytes on the stack.
mhoemmen added a commit to mhoemmen/raft that referenced this issue Sep 27, 2022
Given `char src` and `char dst`,
one should copy them like `dst = src`,
not like `strcpy(&dst, &src)`.

Fixes rapidsai#847.
@rapids-bot rapids-bot bot closed this as completed in #848 Sep 27, 2022
rapids-bot bot pushed a commit that referenced this issue Sep 27, 2022
Given `char src` and `char dst`, one should copy them like `dst = src`, not like `strcpy(&dst, &src)`.

Using `strcpy` in this way invokes undefined behavior, and may cause stack corruption.

Fixes #847.

Authors:
  - Mark Hoemmen (https://github.com/mhoemmen)

Approvers:
  - Corey J. Nolet (https://github.com/cjnolet)

URL: #848
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant