<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>15925</bug_id>
          
          <creation_ts>2025-07-03 20:25:17 +0000</creation_ts>
          <short_desc>Wrong size passed to memcpy in pdb_update_inode leads to missing xattrs when renaming</short_desc>
          <delta_ts>2025-07-11 02:54:03 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>6</classification_id>
          <classification>Yocto Project Subprojects</classification>
          <product>Pseudo</product>
          <component>pseudo</component>
          <version>master</version>
          <rep_platform>All</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>5.3 M2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Daniele Romano">daniele.romano</reporter>
          <assigned_to name="Mark Hatle">mark.hatle</assigned_to>
          <cc>mark.hatle</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>yp.pseudo.watcher</cc>
    
    <cc>yp.watcher</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>102413</commentid>
    <comment_count>0</comment_count>
    <who name="Daniele Romano">daniele.romano</who>
    <bug_when>2025-07-03 20:25:17 +0000</bug_when>
    <thetext>The pdb_update_inode function is unable to find a match and to correctly copy the xattr due to the wrong amount of data copied when cloning msg.


The issue is in the following code in pseudo_db.c:

2160 int pdb_update_inode(pseudo_msg_t *msg) {
.....
.....
2191	memcpy(oldmsg, msg, sizeof(msg) + msg-&gt;pathlen);
2192	found_existing = !pdb_find_file_path(oldmsg);
2193	if (found_existing) {
2194		/* we have an existing file entry */
2195		pdb_copy_xattrs(oldmsg, msg);
2196	}


The memcpy in line 2191 is copying &quot;sizeof(msg) + msg-&gt;pathlen&quot;, but msg is a pointer to a pseudo_msg_t. This means that the amount of bytes copied is equal to msg-&gt;pathlen plus the size of a pointer and not the pseudo_msg_t itself. This issue will lead to a truncated path copied in oldmsg and to the failure of pdb_find_file_path function on line 2193.

The patch attached fixes line 2191 replacing &quot;sizeof(msg)&quot; with &quot;sizeof(pseudo_msg_t)&quot;.

In addition, it fixes the allocation of the oldmsg buffer at line 2167. This is needed to avoid buffer overflows with paths very close to the maximum expected length that is given by the pseudo_path_max() function.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102414</commentid>
    <comment_count>1</comment_count>
      <attachid>5125</attachid>
    <who name="Daniele Romano">daniele.romano</who>
    <bug_when>2025-07-03 20:26:16 +0000</bug_when>
    <thetext>Created attachment 5125
Fix for oldmsg buffer allocation and memcpy data copied</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102449</commentid>
    <comment_count>2</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2025-07-11 02:52:52 +0000</bug_when>
    <thetext>The patch was tested, modified a bit and has been pushed.  See:

https://git.yoctoproject.org/pseudo/commit/?id=d1db9c219abf92f15303486a409292237f1fc790</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>5125</attachid>
            <date>2025-07-03 20:26:16 +0000</date>
            <delta_ts>2025-07-03 20:26:16 +0000</delta_ts>
            <desc>Fix for oldmsg buffer allocation and memcpy data copied</desc>
            <filename>oldmsg buffer allocation and memcpy fix.patch</filename>
            <type>text/plain</type>
            <size>710</size>
            <attacher name="Daniele Romano">daniele.romano</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL3BzZXVkb19kYi5jIGIvcHNldWRvX2RiLmMKaW5kZXggMTRiYWZjYi4uYmRk
MmRjYyAxMDA2NDQKLS0tIGEvcHNldWRvX2RiLmMKKysrIGIvcHNldWRvX2RiLmMKQEAgLTIxNjQs
NyArMjE2NCw3IEBAIHBkYl91cGRhdGVfaW5vZGUocHNldWRvX21zZ190ICptc2cpIHsKICBpbnQg
Zm91bmRfZXhpc3Rpbmc7CiAKICBpZiAoIW9sZG1zZykgewotIG9sZG1zZyA9IG1hbGxvYyhwc2V1
ZG9fcGF0aF9tYXgoKSk7Cisgb2xkbXNnID0gbWFsbG9jKHNpemVvZihwc2V1ZG9fbXNnX3QpICsg
cHNldWRvX3BhdGhfbWF4KCkpOwogIH0KIAogIGNoYXIgKnNxbCA9ICJVUERBVEUgZmlsZXMgIgpA
QCAtMjE4OCw3ICsyMTg4LDcgQEAgcGRiX3VwZGF0ZV9pbm9kZShwc2V1ZG9fbXNnX3QgKm1zZykg
ewogIHBzZXVkb19kaWFnKCJDYW4ndCB1cGRhdGUgdGhlIGlub2RlIG9mIGEgZmlsZSB3aXRob3V0
IGl0cyBwYXRoLlxuIik7CiAgcmV0dXJuIDE7CiAgfQotIG1lbWNweShvbGRtc2csIG1zZywgc2l6
ZW9mKG1zZykgKyBtc2ctPnBhdGhsZW4pOworIG1lbWNweShvbGRtc2csIG1zZywgc2l6ZW9mKHBz
ZXVkb19tc2dfdCkgKyBtc2ctPnBhdGhsZW4pOwogIGZvdW5kX2V4aXN0aW5nID0gIXBkYl9maW5k
X2ZpbGVfcGF0aChvbGRtc2cpOwogIGlmIChmb3VuZF9leGlzdGluZykgewogIC8qIHdlIGhhdmUg
YW4gZXhpc3RpbmcgZmlsZSBlbnRyeSAqLwo=
</data>

          </attachment>
      

    </bug>

</bugzilla>