-
Notifications
You must be signed in to change notification settings - Fork 6
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
desktop.c: warning: ‘__builtin_strncpy’ specified bound 24 equals destination size #19
Comments
Good find. I can't say why it doesn't warn about it during a usual compile but it should, it is a legitimate issue:
Maybe this should have a small wrapper for |
Maybe. Probably above my pay grade! |
|
Let’s just use snprintf() Better to patch in-tree. There is strlcpy() but needs a compat layer so too much faff in this situation. — Edit — sorry typed before I saw above |
Thanks @johanmalm I'll test it out the "debian way" and when all is good I'll do up a PR :) |
Built and tested fine the "debian way" success log
000-purge-strncmp.patchFrom: Mick Mars <[email protected]>
Description: set purge strncmp patch
--- labwc-menu-generator-0.1.0.orig/desktop.c 2024-06-09 07:55:30.082028828 +1000
+++ labwc-menu-generator-0.1.0/desktop.c 2024-06-15 19:13:44.653107939 +1000
@@ -48,25 +48,43 @@
}
/* ll_CC */
- strncpy(llcc, p, sizeof(llcc));
+ int ret = snprintf(llcc, sizeof(llcc), "%s", p);
+ if (ret < 0) {
+ return;
+ }
p = strrchr(llcc, '.');
if (p) {
*p = '\0';
}
/* ll */
- strncpy(ll, llcc, sizeof(ll));
+ ret = snprintf(ll, sizeof(ll), "%s", llcc);
+ if (ret < 0) {
+ return;
+ }
p = strrchr(ll, '_');
if (p) {
*p = '\0';
}
- snprintf(name_ll, sizeof(name_ll), "Name[%s]", ll);
- snprintf(name_llcc, sizeof(name_llcc), "Name[%s]", llcc);
- snprintf(generic_name_ll, sizeof(generic_name_ll),
+ ret = snprintf(name_ll, sizeof(name_ll), "Name[%s]", ll);
+ if (ret < 0) {
+ return;
+ }
+ ret = snprintf(name_llcc, sizeof(name_llcc), "Name[%s]", llcc);
+ if (ret < 0) {
+ return;
+ }
+ ret = snprintf(generic_name_ll, sizeof(generic_name_ll),
"GenericName[%s]", ll);
- snprintf(generic_name_llcc, sizeof(generic_name_llcc),
+ if (ret < 0) {
+ return;
+ }
+ ret = snprintf(generic_name_llcc, sizeof(generic_name_llcc),
"GenericName[%s]", llcc);
+ if (ret < 0) {
+ return;
+ }
}
char *name_ll_get(void) { return name_ll; }
@@ -303,8 +321,14 @@
return;
}
size_t len = strlen(path);
- strncpy(fullname, path, sizeof(fullname));
- strncpy(fullname + len, filename, sizeof(fullname) - len);
+ int ret = snprintf(fullname, sizeof(fullname), "%s", path);
+ if (ret < 0) {
+ return;
+ }
+ ret = snprintf(fullname + len, sizeof(fullname) - len, "%s", filename);
+ if (ret < 0) {
+ return;
+ }
FILE *fp = fopen(fullname, "r");
if (!fp) {
fprintf(stderr, "warn: could not open file %s", filename); Sanity checked standalone as well, even though the |
This is using
debuild -us -uc -rfakeroot
to buildlabwc-menu-generator
labwc-menu-generator_0.1.0-1_amd64.build (warning)
I patched it the "debian way"
debian/patches/000-stringop-truncation.patch
Ran
debuild
againlabwc-menu-generator_0.1.0-1_amd64.build (no warnings, not even `lintian` 😝 )
The
patch
seems too simple-Wstringop-truncation
, patched or originalllcc
is longer thanll
and I realise they are both allocated[24]
and that the- 1
I've inserted is for\0
. Is that a reasonable explanation?The text was updated successfully, but these errors were encountered: