From 45b54f61deac61413cfb38c43e040deb0ef89670 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 15 Mar 2017 03:08:18 +0100 Subject: [PATCH] opkg_cmd: fix segmentation fault in opkg_compare_versions_cmd() 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 --- libopkg/opkg_cmd.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c index ee59021..c26e2c3 100644 --- a/libopkg/opkg_cmd.c +++ b/libopkg/opkg_cmd.c @@ -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 \n" -- 2.25.1