Base64-encode %policy files to ensure it can be presented as strings
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 26 Jun 2009 09:31:57 +0000 (12:31 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 21 Jul 2009 06:42:51 +0000 (09:42 +0300)
- RPMTAG_POLICIES is a string array but there's no guarantee that
  something marked %policy is a plaintext file that can be represented
  as \0-terminated string, base64-encoding them fixes that. Baby steps
  towards making %policy remotely usable, related to RhBug:505066.
- Also remove unnecessary failure code setting, processMetadataFile()
  assumes failure already, and dont try to insert NULL strings in case
  b64encode() or pgpArmorWrap() fails
(cherry picked from commit edbc9ead961fcbeb1733b47405041b653b521bcb)

build/files.c

index d8e11f7..f3cf261 100644 (file)
@@ -18,6 +18,7 @@
 #include <rpm/rpmlog.h>
 
 #include "rpmio/rpmio_internal.h"      /* XXX rpmioSlurp */
+#include "rpmio/base64.h"
 #include "rpmio/fts.h"
 #include "lib/cpio.h"
 #include "lib/rpmfi_internal.h"        /* XXX fi->apath */
@@ -1603,12 +1604,10 @@ static rpmRC processMetadataFile(Package pkg, FileList fl,
        break;
     case RPMTAG_PUBKEYS: {
        if ((xx = pgpReadPkts(fn, &pkt, (size_t *)&pktlen)) <= 0) {
-           rc = RPMRC_FAIL;
            rpmlog(RPMLOG_ERR, _("%s: public key read failed.\n"), fn);
            goto exit;
        }
        if (xx != PGPARMOR_PUBKEY) {
-           rc = RPMRC_FAIL;
            rpmlog(RPMLOG_ERR, _("%s: not an armored public key.\n"), fn);
            goto exit;
        }
@@ -1617,18 +1616,21 @@ static rpmRC processMetadataFile(Package pkg, FileList fl,
     }
     case RPMTAG_POLICIES:
        if ((xx = rpmioSlurp(fn, &pkt, &pktlen)) != 0 || pkt == NULL) {
-           rc = RPMRC_FAIL;
-           rpmlog(RPMLOG_ERR, _("%s: *.te policy read failed.\n"), fn);
+           rpmlog(RPMLOG_ERR, _("%s: policy file read failed.\n"), fn);
            goto exit;
        }
-       apkt = (char *) pkt;    /* XXX unsigned char */
-       pkt = NULL;
+       apkt = b64encode(pkt, pktlen, -1);
        break;
     }
 
-    headerPutString(pkg->header, tag, apkt);
+    if (!apkt) {
+       rpmlog(RPMLOG_ERR, _("%s: failed to encode\n"), fn);
+       goto exit;
+    }
 
+    headerPutString(pkg->header, tag, apkt);
     rc = RPMRC_OK;
+
     if (absolute)
        rc = addFile(fl, fn, NULL);