<?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>15653</bug_id>
          
          <creation_ts>2024-11-19 20:49:42 +0000</creation_ts>
          <short_desc>Field confusion in control files</short_desc>
          <delta_ts>2025-01-17 20:06:07 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>6</classification_id>
          <classification>Yocto Project Subprojects</classification>
          <product>opkg</product>
          <component>opkg</component>
          <version>1.0</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>Undecided</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michal Sieron">michalwsieron</reporter>
          <assigned_to name="Alex Stewart">alex.stewart</assigned_to>
          
          
          
          <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>100216</commentid>
    <comment_count>0</comment_count>
      <attachid>5082</attachid>
    <who name="Michal Sieron">michalwsieron</who>
    <bug_when>2024-11-19 20:49:42 +0000</bug_when>
    <thetext>Created attachment 5082
Fix for field confusion in control files

*Below is a cover letter I wrote before I learned opgk patches don&apos;t go
through the mailing list. Attached is patch with proposed fix for
described issue*

A little bit of background: we have a custom field in our ipk control
files named `Package_name` with a value of the ipk filename, e.g.:
    Package_name: libc6_2.35-r0.ipk

The problem addressed in this patch is happening, because opkg only
checks if first `n` bytes match `Package` string and doesn&apos;t care
whether that string is actually followed by a colon (`:`) or not.

This was especially bad in our case as because of our custom field opkg
was cutting the field at the underscore in `Package_name` and was using
what followed as the actual package name. So in that example of
`Package_name: libc6_2.35-r0.ipk` resulting name of the installed
package was `name: libc6_2.35-r0.ipk`, which of course is totally wrong.

What&apos;s more, because of the space in that parsed package name, all
(pre|post)(install|rm) hooks were broken, as they go through shell in
`pkg.c:pkg_run_script()`, which uses `-c` argument. Because there
is no escaping, it led to error like &quot;no file named `name:`&quot;.
You can see this is caused by a space in the wrongly parsed package name,
which is used as a prefix in name for all `postinstall` hooks and similar.

In my opinion that `-c` should be either removed mandating writing those
hooks as a shell scripts or the whole shell call replaced with a direct
binary execution.

As I am not yet sure, which approach is right here, I am only tackling
name confusion issue here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100245</commentid>
    <comment_count>1</comment_count>
    <who name="Alex Stewart">alex.stewart</who>
    <bug_when>2024-11-21 20:02:55 +0000</bug_when>
    <thetext>Hey Michal; thanks for the patch. Patches *do* actually go through the mailing list at [1]. Though I could pull it from here, I would prefer that it go to the list, just to give others in the community the opportunity to speak about it. Could you resubmit there?

[1] https://lists.yoctoproject.org/g/opkg


Regarding this version of the patch:

Overall, the issue and fix make sense.

What happens if someone calls this `is_field()` implementation with `type` and `line` values that are the same, and do not end with a colon? eg.

```
is_field(&quot;foo&quot;, &quot;foo);
```

It seems like the new `strncmp(&quot;foo&quot;, &quot;foo&quot;, 3)` would succeed and pass through to the colon checks, where the second case (`line[3] == &apos;:&apos;`) would try to index into an undefined memory region. So you might have to do some more processing to avoid an index error.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100248</commentid>
    <comment_count>2</comment_count>
    <who name="Michal Sieron">michalwsieron</who>
    <bug_when>2024-11-21 23:36:33 +0000</bug_when>
    <thetext>&gt; Patches *do* actually go through the mailing list

I really don&apos;t know how I missed that...

&gt; Could you resubmit there?

Sure, just did that.

&gt; What happens if someone calls this `is_field()` implementation with `type`
&gt; and `line` values that are the same, and do not end with a colon? eg.
&gt; 
&gt; ```
&gt; is_field(&quot;foo&quot;, &quot;foo);
&gt; ```
&gt; 
&gt; It seems like the new `strncmp(&quot;foo&quot;, &quot;foo&quot;, 3)` would succeed and pass
&gt; through to the colon checks, where the second case (`line[3] == &apos;:&apos;`) would
&gt; try to index into an undefined memory region. So you might have to do some
&gt; more processing to avoid an index error.

Well, it wouldn&apos;t access undefined memory, as it would read the NULL terminator of the `line`, which would be different from `:` and in that case we would conclude the field doesn&apos;t match.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100254</commentid>
    <comment_count>3</comment_count>
    <who name="Alex Stewart">alex.stewart</who>
    <bug_when>2024-11-22 20:51:00 +0000</bug_when>
    <thetext>Hmm... I was thinking of situations where a null-terminator might not be applied to the end of the string. But on further research, none of those should apply here. So, you&apos;re correct. Objection dropped.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100689</commentid>
    <comment_count>4</comment_count>
    <who name="Alex Stewart">alex.stewart</who>
    <bug_when>2025-01-17 20:06:07 +0000</bug_when>
    <thetext>Fixed as of opkg v0.8.0, by commit c87188d7535684fddb8cf80993c147b215602b63.

https://git.yoctoproject.org/opkg/commit/?id=c87188d7535684fddb8cf80993c147b215602b63</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>5082</attachid>
            <date>2024-11-19 20:49:42 +0000</date>
            <delta_ts>2024-11-19 20:49:42 +0000</delta_ts>
            <desc>Fix for field confusion in control files</desc>
            <filename>0001-parse_util-Avoid-field-confusion-in-is_field.patch</filename>
            <type>text/plain</type>
            <size>1215</size>
            <attacher name="Michal Sieron">michalwsieron</attacher>
            
              <data encoding="base64">RnJvbSAwNzE1MTBmZDMzMzFkMmVhOTRhYWJlYmQzMGI4YjI1MGMzOTUxNGMyIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBNaWNoYWwg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