From 27855634e99f66eef2fbe4ca8837a00b46964cc2 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Sat, 31 May 2008 13:28:05 +0300 Subject: [PATCH] More generic iterators replaced with safer string iterators - additionally ensure rasprintf() will never get passed NULL where string is expected in doScriptExec() --- lib/psm.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/psm.c b/lib/psm.c index 937e85f..b534a95 100644 --- a/lib/psm.c +++ b/lib/psm.c @@ -626,16 +626,18 @@ static void doScriptExec(rpmts ts, ARGV_const_t argv, rpmtd prefixes, } if (rpmtdCount(prefixes) > 0) { - int i; + const char *pfx; char *buf = NULL; /* backwards compatibility */ - rasprintf(&buf, "RPM_INSTALL_PREFIX=%s", rpmtdGetString(prefixes)); - xx = doputenv(buf); - buf = _free(buf); + if ((pfx = rpmtdGetString(prefixes))) { + rasprintf(&buf, "RPM_INSTALL_PREFIX=%s", pfx); + xx = doputenv(buf); + buf = _free(buf); + } - while ((i = rpmtdNext(prefixes)) >= 0) { - rasprintf(&buf, "RPM_INSTALL_PREFIX%d=%s", i, - rpmtdGetString(prefixes)); + while ((pfx = rpmtdNextString(prefixes))) { + rasprintf(&buf, "RPM_INSTALL_PREFIX%d=%s", + rpmtdGetIndex(prefixes), pfx); xx = doputenv(buf); buf = _free(buf); } @@ -861,6 +863,7 @@ static rpmRC runInstScript(rpmpsm psm) rpmRC rc = RPMRC_OK; ARGV_t argv; struct rpmtd_s script, prog; + const char *str; if (fi->h == NULL) /* XXX can't happen */ return RPMRC_FAIL; @@ -871,8 +874,8 @@ static rpmRC runInstScript(rpmpsm psm) goto exit; argv = argvNew(); - while (rpmtdNext(&prog) >= 0) { - argvAdd(&argv, rpmtdGetString(&prog)); + while ((str = rpmtdNextString(&prog))) { + argvAdd(&argv, str); } rc = runScript(psm, fi->h, psm->scriptTag, &argv, -- 2.7.4