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

fix: replace strlcpy with preferred strscpy #30

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

iomz
Copy link

@iomz iomz commented Oct 23, 2024

Since it is preferred to use strscpy over strlcpy for its insecurity, update the only one line where it is used.
This change also solves the build issue when GNU glibc cannot find strlcpy throwing the following error with recent environments:

8:26 iomz@sazanka:~/ghq/github.com/nns779/px4_drv/driver
[develop|✚1…2] ❯❯❯ make
make[1]: Entering directory '/usr/src/linux-headers-6.8.0-47-generic'
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: x86_64-linux-gnu-gcc-13 (Ubuntu 13.2.0-23ubuntu4) 13.2.0
  You are using:           gcc-13 (Ubuntu 13.2.0-23ubuntu4) 13.2.0
  CC [M]  /home/iomz/ghq/github.com/nns779/px4_drv/driver/ptx_chrdev.o
/home/iomz/ghq/github.com/nns779/px4_drv/driver/ptx_chrdev.c: In function ‘ptx_chrdev_context_create’:
/home/iomz/ghq/github.com/nns779/px4_drv/driver/ptx_chrdev.c:569:9: error: implicit declaration of function ‘strlcpy’; did you mean ‘strscpy’? [-Werror=implicit-function-declaration]
  569 |         strlcpy(ctx->devname, devname, sizeof(ctx->devname));
      |         ^~~~~~~
      |         strscpy
/home/iomz/ghq/github.com/nns779/px4_drv/driver/ptx_chrdev.c: At top level:
/home/iomz/ghq/github.com/nns779/px4_drv/driver/ptx_chrdev.c:727:5: warning: no previous prototype for ‘ptx_chrdev_context_reserve’ [-Wmissing-prototypes]
  727 | int ptx_chrdev_context_reserve(struct ptx_chrdev_context *chrdev_ctx,
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:243: /home/iomz/ghq/github.com/nns779/px4_drv/driver/ptx_chrdev.o] Error 1
make[2]: *** [/usr/src/linux-headers-6.8.0-47-generic/Makefile:1925: /home/iomz/ghq/github.com/nns779/px4_drv/driver] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-6.8.0-47-generic'
make[1]: *** [Makefile:240: __sub-make] Error 2
make: *** [Makefile:19: px4_drv.ko] Error 2

cf. https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html

aoirint added a commit to aoirint/px4_drv that referenced this pull request Dec 30, 2024
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 this pull request may close these issues.

1 participant