Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

chore(security): avoid use of strcpy #1159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Saadnajmi
Copy link

Internally, we use this library with React Native. We noticed that Xcode's static analysis would point out a potentially unsafe call to strcpy. We are doing a proper bound check, but to be safer, we could also use something like strncpy / strncpy_s / strlcpy / memcpy to handle this case. Of those, the latter felt the most portable, so I went with that.

Copy link

google-cla bot commented Mar 4, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Saadnajmi
Copy link
Author

Signed the CLA

Copy link
Collaborator

@sergiud sergiud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

Silencing the static analyzer by reimplementing strcpy is not meaningful. Given the bounds are checked I don't understand what the current changes actually fix.

@Saadnajmi
Copy link
Author

Thanks for the PR.

Silencing the static analyzer by reimplementing strcpy is not meaningful. Given the bounds are checked I don't understand what the current changes actually fix.

Fair. I would have preferred to use something like 'strlcpy' which Xcode actually suggested, but I wasn't sure that would be portable enough, as I'm not sure what Google's C / C++ standards are. Would you have an idea?

@Saadnajmi
Copy link
Author

@sergiud Would strlcpy work?
w.r.t what this actually fixes, it's mostly me not wanting to maintain a fork of glog / glog with a patch for this one line. I understand Xcode / clang is over-reporting here since the usage is actually sage, but 🤷‍♂️

@sergiud
Copy link
Collaborator

sergiud commented Apr 7, 2025

@Saadnajmi I suggest we test this in ng-log that supersedes glog which is being deprecated.

Please open a PR there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants