summaryrefslogtreecommitdiff
path: root/lib/psm.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-05-31 13:28:05 +0300
committerPanu Matilainen <pmatilai@redhat.com>2008-05-31 13:28:05 +0300
commit27855634e99f66eef2fbe4ca8837a00b46964cc2 (patch)
treef76d26a2723f817f029a1bc1d3b97bd265692f8f /lib/psm.c
parentc275732c75e23501fb66fa30ee025c2a1a50a736 (diff)
downloadrpm-27855634e99f66eef2fbe4ca8837a00b46964cc2.tar.gz
rpm-27855634e99f66eef2fbe4ca8837a00b46964cc2.tar.bz2
rpm-27855634e99f66eef2fbe4ca8837a00b46964cc2.zip
More generic iterators replaced with safer string iterators
- additionally ensure rasprintf() will never get passed NULL where string is expected in doScriptExec()
Diffstat (limited to 'lib/psm.c')
-rw-r--r--lib/psm.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/psm.c b/lib/psm.c
index 937e85fbc..b534a954d 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,