Skip to contentSkip to conversation

PATCH (ACM): keep binary stream aligned

PATCH Tristan Gingold 1 participant 1 message Sep 4, 2006

lore
Share & tools
lore
#0 lore raw

Hi,

I am currently porting ACM to xen/ia64.
Because ia64 can't handle unaligned accesses, the binary policy file should be aligned. This patch fixes this issue.
(There is the same issue within xen/acm for dumping feature. A patch will follow).

Tested on xen/ia64.

Tristan.

# HG changeset patch
# User gingold@virtu10
# Node ID a0507fa13cc774afd707153477af10081e42cedb # Parent afe74d7dcd8b7be768b0ffdb16ccca3b90e26463 Keep stream aligned.

tools/security/secpol_xml2bin.c +6 -4
diff -r afe74d7dcd8b -r a0507fa13cc7 tools/security/secpol_xml2bin.c
@@ -979,13 +979,15 @@ unsigned char *write_policy_reference_bi
     unsigned char *buf, *ptr;
     struct acm_policy_reference_buffer *pr_header;
     u_int32_t len;
+    u_int32_t name_len;
 
     if (policy_reference_name == NULL) {
         printf("ERROR: No policy reference name found.\n");
         exit(EXIT_FAILURE);
     }
-    len = (sizeof(struct acm_policy_reference_buffer) +
-           strlen(policy_reference_name) + 1);
+    name_len = strlen(policy_reference_name) + 1; /* strend '\0' */
+    len = sizeof(struct acm_policy_reference_buffer) + name_len;
+    len = (len + 7) & ~7; /* Alignment.  */
     buf = malloc(len);
     ptr = buf;
 
@@ -994,9 +996,9 @@ unsigned char *write_policy_reference_bi
             ("ERROR: out of memory allocating label reference buffer.\n");
         exit(EXIT_FAILURE);
     }
+    memset (buf, 0, len);
     pr_header = (struct acm_policy_reference_buffer *) buf;
-    pr_header->len =
-        htonl(strlen(policy_reference_name) + 1 /* strend \'0' */ );
+    pr_header->len = htonl(name_len);
     ptr += sizeof(struct acm_policy_reference_buffer);
     strcpy((char *) ptr, policy_reference_name);
 

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel