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

Use strlcpy instead of strncpy #395

Closed
wants to merge 1 commit into from
Closed

Conversation

yuzibo
Copy link

@yuzibo yuzibo commented Nov 20, 2024

On Debian, it will report as below:
native/syscalls.c:864:22: error: passing argument 2 of ‘strncpy’ from incompatible pointer type [-Wincompatible-pointer-types]
864 | strncpy(buf, &address_->sun_path, 108);
| ^~~~~~~~~~~~~~~~~~~
| |
| char (*)[108]

On Debian, it will report as below:
native/syscalls.c:864:22: error: passing argument 2 of ‘strncpy’ from incompatible pointer type [-Wincompatible-pointer-types]
  864 |         strncpy(buf, &address_->sun_path, 108);
      |                      ^~~~~~~~~~~~~~~~~~~
      |                      |
      |                      char (*)[108]

Signed-off-by: Bo YU <[email protected]>
@yuzibo
Copy link
Author

yuzibo commented Nov 20, 2024

See build log

@remram44 remram44 added the T-bug Type: A fix for unwanted behavior, NOT a new feature or a simple enhancement label Nov 22, 2024
@yuzibo
Copy link
Author

yuzibo commented Nov 22, 2024

hmm, maybe we still use strncpy here? or could you help me to have a look at these tests failed?

@remram44
Copy link
Member

I'm traveling now but I'm happy to fix the build when I'm back, don't worry about it.

@yuzibo
Copy link
Author

yuzibo commented Nov 22, 2024

I'm traveling now but I'm happy to fix the build when I'm back, don't worry about it.

Okay, thank you. Please enjoy your traveling.:)

@remram44
Copy link
Member

I can confirm that removing the & fixes the build on gcc 14. I don't see a problem with the use of strncpy so I am going to stick with it as it's more standard.

@remram44
Copy link
Member

Fixed by dc7e12b.

@remram44 remram44 closed this Nov 25, 2024
@yuzibo
Copy link
Author

yuzibo commented Nov 26, 2024

Thanks for your quickly fix.

But I have one concern here, can we ensure address_->sun_path is less than 108? or is address_->sun_path one valid string with \0?

@remram44
Copy link
Member

Yes, the struct is:

struct sockaddr_un {
    sa_family_t sun_family;     /* AF_UNIX */
    char        sun_path[108];  /* Pathname */
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: A fix for unwanted behavior, NOT a new feature or a simple enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants