Fix segfault in pkg version against the ports tree

PR:		224023
Reported by:	jrm, kib, Trond.Endrestol@ximalas.info
Tested by:	jrm (an early version of the patch)
This commit is contained in:
Baptiste Daroussin 2017-12-05 16:22:01 +00:00
parent bcf265d0e1
commit bfd7582edd
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=455589
2 changed files with 29 additions and 0 deletions

View File

@ -2,6 +2,7 @@
PORTNAME= pkg
DISTVERSION= 1.10.3
PORTREVISION= 1
_PKG_VERSION= ${DISTVERSION}
CATEGORIES= ports-mgmt
MASTER_SITES= \

View File

@ -0,0 +1,28 @@
diff --git src/version.c src/version.c
index d265776b..92c18060 100644
--- src/version.c
+++ src/version.c
@@ -601,6 +601,8 @@ exec_buf(UT_string *res, char **argv) {
if (errno != EINTR)
return (-1);
}
+ if (WEXITSTATUS(pstat) != 0)
+ return (-1);
return (utstring_len(res));
}
@@ -716,11 +718,13 @@ port_version(UT_string *cmd, const char *portsdir, const char *origin,
argv[3] = "flavors-package-names";
argv[4] = NULL;
- if (exec_buf(cmd, argv) != 0) {
+ if (exec_buf(cmd, argv) > 0) {
output = utstring_body(cmd);
while ((walk = strsep(&output, "\n")) != NULL) {
name = walk;
walk = strrchr(walk, '-');
+ if (walk == NULL)
+ continue;
walk[0] = '\0';
walk++;
if (strcmp(name, pkgname) == 0) {