Bug 13380 - Freeing an uninitialized pointer. (pkg->tags)
Summary: Freeing an uninitialized pointer. (pkg->tags)
Status: RESOLVED FIXED
Alias: None
Product: opkg
Classification: Yocto Project Subprojects
Component: opkg (show other bugs)
Version: 1.0
Hardware: All Multiple
: Undecided minor
Target Milestone: ---
Assignee: Alejandro del Castillo
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2019-06-07 14:46 UTC by lnksz.dev
Modified: 2019-09-16 15:04 UTC (History)
0 users

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Don't know


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lnksz.dev 2019-06-07 14:46:05 UTC
Freeing an uninitialized pointer.

```c
pkg_t pkg;
pkg_init_from_file(&next, "/tmp/some.ipk"); // This calls pkg_init() under the hood
// Use pkg here
pkg_deinit(&pkg); // ==> free(pkg->tags) freeing an uninitialized pointer
```


This is not surfacing if one uses the pkg_new() call, as the underlaying calloc() sets this to 0, which could be NULL, so the free is ok. But as the described method is also legit by the API and spares a possible memory leak, the init should be added.

patch:
```
--- a/libopkg/pkg.c
+++ b/libopkg/pkg.c
@@ -85,6 +85,7 @@ pkg_init(pkg_t *pkg)
      pkg->maintainer = NULL;
      pkg->section = NULL;
      pkg->description = NULL;
+     pkg->tags = NULL;
      pkg->state_want = SW_UNKNOWN;
      pkg->wanted_by = pkg_vec_alloc();
      pkg->state_flag = SF_OK;

```
Comment 1 Alejandro del Castillo 2019-09-16 15:04:38 UTC
Applied patch on 7e032d8720b34722b3d9be732cb8620912e4dc96