opkg_cmd: fix segmentation fault in opkg_compare_versions_cmd()
authorJo-Philipp Wich <jo@mein.io>
Wed, 15 Mar 2017 02:08:18 +0000 (03:08 +0100)
committerJo-Philipp Wich <jo@mein.io>
Wed, 15 Mar 2017 02:08:18 +0000 (03:08 +0100)
Due to the fact that we're using blob buffers internally now we cannot simpyl
call parse_version() on an uninitialized struct.

Properly create the temporary packages using pkg_new() and deallocated them
using pkg_deinit() and free().

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libopkg/opkg_cmd.c

index ee5902175a983c79b46657976f19cb1badddbcac..c26e2c384fe27fe7e966f5060e3e94fef5487c6e 100644 (file)
@@ -1217,12 +1217,21 @@ static int opkg_search_cmd(int argc, char **argv)
 
 static int opkg_compare_versions_cmd(int argc, char **argv)
 {
+       int rc;
+       pkg_t *p1, *p2;
+
        if (argc == 3) {
                /* this is a bit gross */
-               struct pkg p1, p2;
-               parse_version(&p1, argv[0]);
-               parse_version(&p2, argv[2]);
-               return pkg_version_satisfied(&p1, &p2, argv[1]) ? 0 : 1;
+               p1 = pkg_new();
+               p2 = pkg_new();
+               parse_version(p1, argv[0]);
+               parse_version(p2, argv[2]);
+               rc = pkg_version_satisfied(p1, p2, argv[1]);
+               pkg_deinit(p1);
+               pkg_deinit(p2);
+               free(p1);
+               free(p2);
+               return rc ? 0 : 1;
        } else {
                opkg_msg(ERROR,
                         "opkg compare_versions <v1> <op> <v2>\n"