<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:宋体;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:等线;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"\@等线";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"\@宋体";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        text-align:justify;
        text-justify:inter-ideograph;
        font-size:10.5pt;
        font-family:等线;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin:0cm;
        margin-bottom:.0001pt;
        text-align:justify;
        text-justify:inter-ideograph;
        text-indent:21.0pt;
        font-size:10.5pt;
        font-family:等线;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:宋体;}
span.EmailStyle19
        {mso-style-type:personal-compose;
        font-family:等线;
        color:windowtext;}
span.jlqj4b
        {mso-style-name:jlqj4b;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:等线;}
/* Page Definitions */
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="ZH-CN" link="#0563C1" vlink="#954F72" style="text-justify-trim:punctuation">
<div class="WordSection1">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:12.0pt">Hello, <o:p></o:p></span></b></p>
<p class="MsoNormal" style="text-indent:18.0pt"><b><span lang="EN-US" style="font-size:12.0pt">There are two resource leak problems and patches here.<o:p></o:p></span></b></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">Problem 1</span></b><span lang="EN-US" style="font-size:12.0pt">: Resource leakage<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">File</span></b><span lang="EN-US" style="font-size:12.0pt">: erofs-utils/lib/xattr.c<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">Function</span></b><span lang="EN-US" style="font-size:12.0pt">: erofs_get_selabel_xattr<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">Statement</span></b><span lang="EN-US" style="font-size:12.0pt">: ret = asprintf(&fspath, "/%s", erofs_fspath(srcpath));<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:84.0pt;mso-para-margin-left:8.0gd"><span lang="EN-US" style="font-size:12.0pt">if (ret <= 0)<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:105.0pt;mso-para-margin-left:10.0gd"><span lang="EN-US" style="font-size:12.0pt">return ERR_PTR(-ENOMEM);<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">Analysis</span></b><span lang="EN-US" style="font-size:12.0pt">:
</span><span class="jlqj4b"><span lang="EN" style="font-size:12.0pt">When the asprintf function fails, it returns -1</span></span><span lang="EN-US" style="font-size:12.0pt">, so the judgment condition should be ret<0. Return when ret=0, the storage pointed
 to by fspath will be leaked<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">Patch</span></b><span lang="EN-US" style="font-size:12.0pt">: if (ret < 0)<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><span lang="EN-US" style="font-size:12.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">Problem 2</span></b><span lang="EN-US" style="font-size:12.0pt">: Resource leakage<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">File</span></b><span lang="EN-US" style="font-size:12.0pt">: erofs-utils/lib/inode.c<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">Function</span></b><span lang="EN-US" style="font-size:12.0pt">: erofs_droid_inode_fsconfig<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">Statement</span></b><span lang="EN-US" style="font-size:12.0pt">: if (asprintf(&decorated, "%s/%s", cfg.mount_point, erofs_fspath(path))
 <= 0)<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:105.0pt;mso-para-margin-left:10.0gd"><span lang="EN-US" style="font-size:12.0pt">return -ENOMEM;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">Analysis</span></b><span lang="EN-US" style="font-size:12.0pt">:
</span><span class="jlqj4b"><span lang="EN" style="font-size:12.0pt">When the asprintf function fails, it returns -1</span></span><span lang="EN-US" style="font-size:12.0pt">, so the judgment condition should be ret<0. Return when asprintf(&decorated, "%s/%s",
 cfg.mount_point, erofs_fspath(path)) = 0, the storage pointed to by decorated will be leaked<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:21.0pt;mso-para-margin-left:2.0gd"><b><span lang="EN-US" style="font-size:12.0pt">Patch</span></b><span lang="EN-US" style="font-size:12.0pt">: if (asprintf(&decorated, "%s/%s", cfg.mount_point, erofs_fspath(path)) <
 0)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span lang="EN-US">Thank you!<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span lang="EN-US">Jinbao Liu<o:p></o:p></span></b></p>
<p class="MsoNormal"><b><span lang="EN-US"><o:p> </o:p></span></b></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
#/******本邮件及其附件含有小米公司的保密信息,仅限于发送给上面地址中列出的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本邮件! This e-mail and its attachments contain confidential information from XIAOMI, which is intended only for the person or entity whose address
 is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in
 error, please notify the sender by phone or email immediately and delete it!******/#
</body>
</html>