Messages in this thread | | | Date | Tue, 9 Apr 2024 06:32:49 -0700 | From | Christoph Hellwig <> | Subject | Re: [PATCH] xfs: xattr: replace strncpy and check for truncation |
| |
On Fri, Apr 05, 2024 at 07:45:08PM +0000, Justin Stitt wrote: > - memcpy(offset, prefix, prefix_len); > - offset += prefix_len; > - strncpy(offset, (char *)name, namelen); /* real name */ > - offset += namelen; > - *offset = '\0'; > + > + combined_len = prefix_len + namelen; > + > + /* plus one byte for \0 */ > + actual_len = scnprintf(offset, combined_len + 1, "%s%s", prefix, name); > + > + if (actual_len < combined_len)
Shouldn't this be a != ?
That being said I think this is actually wrong - the attr names are not NULL-terminated on disk, which is why we have the explicit zero terminataion above.
How was this tested?
| |