From: Jo-Philipp Wich Date: Wed, 15 Mar 2017 02:08:18 +0000 (+0100) Subject: opkg_cmd: fix segmentation fault in opkg_compare_versions_cmd() X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=45b54f61deac61413cfb38c43e040deb0ef89670;p=oweals%2Fopkg-lede.git 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 --- 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"