[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] Merge



# HG changeset patch
# User Tim Deegan <Tim.Deegan@xxxxxxxxxxxxx>
# Date 1170089422 0
# Node ID 21d6135f522fb309b830f803c4b6d289f2b5e092
# Parent  99d36a1530249cc4b918e83dfc5a62324f63b3bf
# Parent  44eb80f50725557a74f491bae0bd9c4a30bdf793
Merge
---
 xen/acm/acm_chinesewall_hooks.c             |   44 +++++------
 xen/acm/acm_core.c                          |   44 +++--------
 xen/acm/acm_policy.c                        |  106 +++++++++++++-------------
 xen/acm/acm_simple_type_enforcement_hooks.c |   34 ++++----
 xen/arch/ia64/linux-xen/setup.c             |    5 -
 xen/arch/ia64/xen/dom_fw.c                  |   49 ++++++------
 xen/arch/ia64/xen/domain.c                  |    3 
 xen/arch/ia64/xen/gdbstub.c                 |    2 
 xen/arch/ia64/xen/oprofile/perfmon.c        |    2 
 xen/arch/powerpc/domain_build.c             |    2 
 xen/arch/powerpc/of-devtree.c               |    3 
 xen/arch/powerpc/ofd_fixup.c                |    2 
 xen/arch/x86/cpu/common.c                   |    6 -
 xen/arch/x86/cpu/cyrix.c                    |    7 -
 xen/arch/x86/cpu/intel.c                    |    2 
 xen/arch/x86/dmi_scan.c                     |    2 
 xen/arch/x86/domain_build.c                 |    2 
 xen/arch/x86/hvm/intercept.c                |    6 -
 xen/arch/x86/setup.c                        |   28 +++----
 xen/common/kexec.c                          |    2 
 xen/common/keyhandler.c                     |    5 -
 xen/common/libelf/libelf-dominfo.c          |   16 ++--
 xen/common/libelf/libelf-private.h          |   13 +--
 xen/common/perfc.c                          |    3 
 xen/common/rangeset.c                       |    2 
 xen/common/string.c                         |  111 ++++++----------------------
 xen/drivers/char/console.c                  |    4 -
 xen/include/acm/acm_endian.h                |   52 ++-----------
 xen/include/xen/byteorder/big_endian.h      |    4 -
 xen/include/xen/byteorder/little_endian.h   |    4 -
 xen/include/xen/string.h                    |   29 +++----
 31 files changed, 238 insertions(+), 356 deletions(-)

diff -r 99d36a153024 -r 21d6135f522f xen/acm/acm_chinesewall_hooks.c
--- a/xen/acm/acm_chinesewall_hooks.c   Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/acm/acm_chinesewall_hooks.c   Mon Jan 29 16:50:22 2007 +0000
@@ -132,26 +132,26 @@ static int chwall_dump_policy(u8 * buf, 
     if (buf_size < sizeof(struct acm_chwall_policy_buffer))
         return -EINVAL;
 
-    chwall_buf->chwall_max_types = htonl(chwall_bin_pol.max_types);
-    chwall_buf->chwall_max_ssidrefs = htonl(chwall_bin_pol.max_ssidrefs);
-    chwall_buf->policy_code = htonl(ACM_CHINESE_WALL_POLICY);
+    chwall_buf->chwall_max_types = cpu_to_be32(chwall_bin_pol.max_types);
+    chwall_buf->chwall_max_ssidrefs = cpu_to_be32(chwall_bin_pol.max_ssidrefs);
+    chwall_buf->policy_code = cpu_to_be32(ACM_CHINESE_WALL_POLICY);
     chwall_buf->chwall_ssid_offset =
-        htonl(sizeof(struct acm_chwall_policy_buffer));
+        cpu_to_be32(sizeof(struct acm_chwall_policy_buffer));
     chwall_buf->chwall_max_conflictsets =
-        htonl(chwall_bin_pol.max_conflictsets);
+        cpu_to_be32(chwall_bin_pol.max_conflictsets);
     chwall_buf->chwall_conflict_sets_offset =
-        htonl(ntohl(chwall_buf->chwall_ssid_offset) +
+        cpu_to_be32(be32_to_cpu(chwall_buf->chwall_ssid_offset) +
               sizeof(domaintype_t) * chwall_bin_pol.max_ssidrefs *
               chwall_bin_pol.max_types);
     chwall_buf->chwall_running_types_offset =
-        htonl(ntohl(chwall_buf->chwall_conflict_sets_offset) +
+        cpu_to_be32(be32_to_cpu(chwall_buf->chwall_conflict_sets_offset) +
               sizeof(domaintype_t) * chwall_bin_pol.max_conflictsets *
               chwall_bin_pol.max_types);
     chwall_buf->chwall_conflict_aggregate_offset =
-        htonl(ntohl(chwall_buf->chwall_running_types_offset) +
+        cpu_to_be32(be32_to_cpu(chwall_buf->chwall_running_types_offset) +
               sizeof(domaintype_t) * chwall_bin_pol.max_types);
 
-    ret = ntohl(chwall_buf->chwall_conflict_aggregate_offset) +
+    ret = be32_to_cpu(chwall_buf->chwall_conflict_aggregate_offset) +
         sizeof(domaintype_t) * chwall_bin_pol.max_types;
 
     ret = (ret + 7) & ~7;
@@ -160,21 +160,21 @@ static int chwall_dump_policy(u8 * buf, 
         return -EINVAL;
 
     /* now copy buffers over */
-    arrcpy16((u16 *) (buf + ntohl(chwall_buf->chwall_ssid_offset)),
+    arrcpy16((u16 *) (buf + be32_to_cpu(chwall_buf->chwall_ssid_offset)),
              chwall_bin_pol.ssidrefs,
              chwall_bin_pol.max_ssidrefs * chwall_bin_pol.max_types);
 
     arrcpy16((u16 *) (buf +
-                      ntohl(chwall_buf->chwall_conflict_sets_offset)),
+                      be32_to_cpu(chwall_buf->chwall_conflict_sets_offset)),
              chwall_bin_pol.conflict_sets,
              chwall_bin_pol.max_conflictsets * chwall_bin_pol.max_types);
 
     arrcpy16((u16 *) (buf +
-                      ntohl(chwall_buf->chwall_running_types_offset)),
+                      be32_to_cpu(chwall_buf->chwall_running_types_offset)),
              chwall_bin_pol.running_types, chwall_bin_pol.max_types);
 
     arrcpy16((u16 *) (buf +
-                      ntohl(chwall_buf->chwall_conflict_aggregate_offset)),
+                      
be32_to_cpu(chwall_buf->chwall_conflict_aggregate_offset)),
              chwall_bin_pol.conflict_aggregate_set,
              chwall_bin_pol.max_types);
     return ret;
@@ -267,20 +267,20 @@ static int chwall_set_policy(u8 * buf, u
         return -EINVAL;
 
     /* rewrite the policy due to endianess */
-    chwall_buf->policy_code = ntohl(chwall_buf->policy_code);
-    chwall_buf->policy_version = ntohl(chwall_buf->policy_version);
-    chwall_buf->chwall_max_types = ntohl(chwall_buf->chwall_max_types);
+    chwall_buf->policy_code = be32_to_cpu(chwall_buf->policy_code);
+    chwall_buf->policy_version = be32_to_cpu(chwall_buf->policy_version);
+    chwall_buf->chwall_max_types = be32_to_cpu(chwall_buf->chwall_max_types);
     chwall_buf->chwall_max_ssidrefs =
-        ntohl(chwall_buf->chwall_max_ssidrefs);
+        be32_to_cpu(chwall_buf->chwall_max_ssidrefs);
     chwall_buf->chwall_max_conflictsets =
-        ntohl(chwall_buf->chwall_max_conflictsets);
-    chwall_buf->chwall_ssid_offset = ntohl(chwall_buf->chwall_ssid_offset);
+        be32_to_cpu(chwall_buf->chwall_max_conflictsets);
+    chwall_buf->chwall_ssid_offset = 
be32_to_cpu(chwall_buf->chwall_ssid_offset);
     chwall_buf->chwall_conflict_sets_offset =
-        ntohl(chwall_buf->chwall_conflict_sets_offset);
+        be32_to_cpu(chwall_buf->chwall_conflict_sets_offset);
     chwall_buf->chwall_running_types_offset =
-        ntohl(chwall_buf->chwall_running_types_offset);
+        be32_to_cpu(chwall_buf->chwall_running_types_offset);
     chwall_buf->chwall_conflict_aggregate_offset =
-        ntohl(chwall_buf->chwall_conflict_aggregate_offset);
+        be32_to_cpu(chwall_buf->chwall_conflict_aggregate_offset);
 
     /* policy type and version checks */
     if ((chwall_buf->policy_code != ACM_CHINESE_WALL_POLICY) ||
diff -r 99d36a153024 -r 21d6135f522f xen/acm/acm_core.c
--- a/xen/acm/acm_core.c        Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/acm/acm_core.c        Mon Jan 29 16:50:22 2007 +0000
@@ -62,35 +62,20 @@ struct acm_binary_policy acm_bin_pol;
 /* acm binary policy lock */
 DEFINE_RWLOCK(acm_bin_pol_rwlock);
 
-/* until we have endian support in Xen, we discover it at runtime */
-u8 little_endian = 1;
-void
-acm_set_endian(void)
-{
-    u32 test = 1;
-    if (*((u8 *)&test) == 1)
-    {
-        printkd("ACM module running in LITTLE ENDIAN.\n");
-        little_endian = 1;
-    }
-    else
-    {
-        printkd("ACM module running in BIG ENDIAN.\n");
-        little_endian = 0;
-    }
-}
-
-int
-acm_set_policy_reference(u8 * buf, u32 buf_size)
+int
+acm_set_policy_reference(u8 *buf, u32 buf_size)
 {
     struct acm_policy_reference_buffer *pr = (struct 
acm_policy_reference_buffer *)buf;
-    acm_bin_pol.policy_reference_name = (char *)xmalloc_array(u8, 
ntohl(pr->len));
+    acm_bin_pol.policy_reference_name = (char *)xmalloc_array(u8, 
be32_to_cpu(pr->len));
 
     if (!acm_bin_pol.policy_reference_name)
         return -ENOMEM;
 
-    strcpy(acm_bin_pol.policy_reference_name, (char *)(buf + sizeof(struct 
acm_policy_reference_buffer)));
-    printk("%s: Activating policy %s\n", __func__, 
acm_bin_pol.policy_reference_name);
+    strlcpy(acm_bin_pol.policy_reference_name,
+            (char *)(buf + sizeof(struct acm_policy_reference_buffer)),
+            be32_to_cpu(pr->len));
+    printk("%s: Activating policy %s\n", __func__,
+           acm_bin_pol.policy_reference_name);
     return 0;
 }
 
@@ -105,9 +90,10 @@ acm_dump_policy_reference(u8 *buf, u32 b
         return -EINVAL;
 
     memset(buf, 0, ret);
-    pr_buf->len = htonl(strlen(acm_bin_pol.policy_reference_name) + 1); /* 
including stringend '\0' */
-    strcpy((char *)(buf + sizeof(struct acm_policy_reference_buffer)),
-           acm_bin_pol.policy_reference_name);
+    pr_buf->len = cpu_to_be32(strlen(acm_bin_pol.policy_reference_name) + 1); 
/* including stringend '\0' */
+    strlcpy((char *)(buf + sizeof(struct acm_policy_reference_buffer)),
+            acm_bin_pol.policy_reference_name,
+            be32_to_cpu(pr_buf->len));
     return ret;
 }
 
@@ -198,7 +184,7 @@ acm_is_policy(char *buf, unsigned long l
         return 0;
 
     pol = (struct acm_policy_buffer *)buf;
-    return ntohl(pol->magic) == ACM_MAGIC;
+    return be32_to_cpu(pol->magic) == ACM_MAGIC;
 }
 
 
@@ -213,7 +199,7 @@ acm_setup(char *policy_start,
         return rc;
 
     pol = (struct acm_policy_buffer *)policy_start;
-    if (ntohl(pol->magic) != ACM_MAGIC)
+    if (be32_to_cpu(pol->magic) != ACM_MAGIC)
         return rc;
 
     rc = do_acm_set_policy((void *)policy_start, (u32)policy_len);
@@ -236,8 +222,6 @@ acm_init(char *policy_start,
          unsigned long policy_len)
 {
     int ret = ACM_OK;
-
-    acm_set_endian();
 
     /* first try to load the boot policy (uses its own locks) */
     acm_setup(policy_start, policy_len);
diff -r 99d36a153024 -r 21d6135f522f xen/acm/acm_policy.c
--- a/xen/acm/acm_policy.c      Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/acm/acm_policy.c      Mon Jan 29 16:50:22 2007 +0000
@@ -63,9 +63,9 @@ do_acm_set_policy(void *buf, u32 buf_siz
 {
     struct acm_policy_buffer *pol = (struct acm_policy_buffer *)buf;
     /* some sanity checking */
-    if ((ntohl(pol->magic) != ACM_MAGIC) ||
-        (buf_size != ntohl(pol->len)) ||
-        (ntohl(pol->policy_version) != ACM_POLICY_VERSION))
+    if ((be32_to_cpu(pol->magic) != ACM_MAGIC) ||
+        (buf_size != be32_to_cpu(pol->len)) ||
+        (be32_to_cpu(pol->policy_version) != ACM_POLICY_VERSION))
     {
         printk("%s: ERROR in Magic, Version, or buf size.\n", __func__);
         goto error_free;
@@ -73,8 +73,8 @@ do_acm_set_policy(void *buf, u32 buf_siz
 
     if (acm_active_security_policy == ACM_POLICY_UNDEFINED) {
         /* setup the policy with the boot policy */
-        if (acm_init_binary_policy((ntohl(pol->secondary_policy_code) << 4) |
-                                   ntohl(pol->primary_policy_code))) {
+        if (acm_init_binary_policy((be32_to_cpu(pol->secondary_policy_code) << 
4) |
+                                   be32_to_cpu(pol->primary_policy_code))) {
             goto error_free;
         }
         acm_active_security_policy =
@@ -82,8 +82,8 @@ do_acm_set_policy(void *buf, u32 buf_siz
     }
 
     /* once acm_active_security_policy is set, it cannot be changed */
-    if ((ntohl(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) ||
-        (ntohl(pol->secondary_policy_code) != 
acm_bin_pol.secondary_policy_code))
+    if ((be32_to_cpu(pol->primary_policy_code) != 
acm_bin_pol.primary_policy_code) ||
+        (be32_to_cpu(pol->secondary_policy_code) != 
acm_bin_pol.secondary_policy_code))
     {
         printkd("%s: Wrong policy type in boot policy!\n", __func__);
         goto error_free;
@@ -93,21 +93,21 @@ do_acm_set_policy(void *buf, u32 buf_siz
     write_lock(&acm_bin_pol_rwlock);
 
     /* set label reference name */
-    if (acm_set_policy_reference(buf + ntohl(pol->policy_reference_offset),
-                                 ntohl(pol->primary_buffer_offset) -
-                                 ntohl(pol->policy_reference_offset)))
+    if (acm_set_policy_reference(buf + 
be32_to_cpu(pol->policy_reference_offset),
+                                 be32_to_cpu(pol->primary_buffer_offset) -
+                                 be32_to_cpu(pol->policy_reference_offset)))
         goto error_lock_free;
 
     /* set primary policy data */
-    if (acm_primary_ops->set_binary_policy(buf + 
ntohl(pol->primary_buffer_offset),
-                                           ntohl(pol->secondary_buffer_offset) 
-
-                                           ntohl(pol->primary_buffer_offset)))
+    if (acm_primary_ops->set_binary_policy(buf + 
be32_to_cpu(pol->primary_buffer_offset),
+                                           
be32_to_cpu(pol->secondary_buffer_offset) -
+                                           
be32_to_cpu(pol->primary_buffer_offset)))
         goto error_lock_free;
 
     /* set secondary policy data */
-    if (acm_secondary_ops->set_binary_policy(buf + 
ntohl(pol->secondary_buffer_offset),
-                                             ntohl(pol->len) - 
-                                             
ntohl(pol->secondary_buffer_offset)))
+    if (acm_secondary_ops->set_binary_policy(buf + 
be32_to_cpu(pol->secondary_buffer_offset),
+                                             be32_to_cpu(pol->len) - 
+                                             
be32_to_cpu(pol->secondary_buffer_offset)))
         goto error_lock_free;
 
     write_unlock(&acm_bin_pol_rwlock);
@@ -136,38 +136,38 @@ acm_get_policy(XEN_GUEST_HANDLE(void) bu
     read_lock(&acm_bin_pol_rwlock);
 
     bin_pol = (struct acm_policy_buffer *)policy_buffer;
-    bin_pol->magic = htonl(ACM_MAGIC);
-    bin_pol->primary_policy_code = htonl(acm_bin_pol.primary_policy_code);
-    bin_pol->secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code);
-
-    bin_pol->len = htonl(sizeof(struct acm_policy_buffer));
-    bin_pol->policy_reference_offset = htonl(ntohl(bin_pol->len));
-    bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len));
-    bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
+    bin_pol->magic = cpu_to_be32(ACM_MAGIC);
+    bin_pol->primary_policy_code = 
cpu_to_be32(acm_bin_pol.primary_policy_code);
+    bin_pol->secondary_policy_code = 
cpu_to_be32(acm_bin_pol.secondary_policy_code);
+
+    bin_pol->len = cpu_to_be32(sizeof(struct acm_policy_buffer));
+    bin_pol->policy_reference_offset = cpu_to_be32(be32_to_cpu(bin_pol->len));
+    bin_pol->primary_buffer_offset = cpu_to_be32(be32_to_cpu(bin_pol->len));
+    bin_pol->secondary_buffer_offset = cpu_to_be32(be32_to_cpu(bin_pol->len));
      
-    ret = acm_dump_policy_reference(policy_buffer + 
ntohl(bin_pol->policy_reference_offset),
-                                    buf_size - 
ntohl(bin_pol->policy_reference_offset));
-    if (ret < 0)
-        goto error_free_unlock;
-
-    bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
-    bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len));
-
-    ret = acm_primary_ops->dump_binary_policy (policy_buffer + 
ntohl(bin_pol->primary_buffer_offset),
-                                               buf_size - 
ntohl(bin_pol->primary_buffer_offset));
-    if (ret < 0)
-        goto error_free_unlock;
-
-    bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
-    bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
-
-    ret = acm_secondary_ops->dump_binary_policy(policy_buffer + 
ntohl(bin_pol->secondary_buffer_offset),
-                                                buf_size - 
ntohl(bin_pol->secondary_buffer_offset));
-    if (ret < 0)
-        goto error_free_unlock;
-
-    bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
-    if (copy_to_guest(buf, policy_buffer, ntohl(bin_pol->len)))
+    ret = acm_dump_policy_reference(policy_buffer + 
be32_to_cpu(bin_pol->policy_reference_offset),
+                                    buf_size - 
be32_to_cpu(bin_pol->policy_reference_offset));
+    if (ret < 0)
+        goto error_free_unlock;
+
+    bin_pol->len = cpu_to_be32(be32_to_cpu(bin_pol->len) + ret);
+    bin_pol->primary_buffer_offset = cpu_to_be32(be32_to_cpu(bin_pol->len));
+
+    ret = acm_primary_ops->dump_binary_policy (policy_buffer + 
be32_to_cpu(bin_pol->primary_buffer_offset),
+                                               buf_size - 
be32_to_cpu(bin_pol->primary_buffer_offset));
+    if (ret < 0)
+        goto error_free_unlock;
+
+    bin_pol->len = cpu_to_be32(be32_to_cpu(bin_pol->len) + ret);
+    bin_pol->secondary_buffer_offset = cpu_to_be32(be32_to_cpu(bin_pol->len));
+
+    ret = acm_secondary_ops->dump_binary_policy(policy_buffer + 
be32_to_cpu(bin_pol->secondary_buffer_offset),
+                                                buf_size - 
be32_to_cpu(bin_pol->secondary_buffer_offset));
+    if (ret < 0)
+        goto error_free_unlock;
+
+    bin_pol->len = cpu_to_be32(be32_to_cpu(bin_pol->len) + ret);
+    if (copy_to_guest(buf, policy_buffer, be32_to_cpu(bin_pol->len)))
         goto error_free_unlock;
 
     read_unlock(&acm_bin_pol_rwlock);
@@ -204,12 +204,12 @@ acm_dump_statistics(XEN_GUEST_HANDLE(voi
     if (len2 < 0)
         goto error_lock_free;
 
-    acm_stats.magic = htonl(ACM_MAGIC);
-    acm_stats.primary_policy_code = htonl(acm_bin_pol.primary_policy_code);
-    acm_stats.secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code);
-    acm_stats.primary_stats_offset = htonl(sizeof(struct acm_stats_buffer));
-    acm_stats.secondary_stats_offset = htonl(sizeof(struct acm_stats_buffer) + 
len1);
-    acm_stats.len = htonl(sizeof(struct acm_stats_buffer) + len1 + len2);
+    acm_stats.magic = cpu_to_be32(ACM_MAGIC);
+    acm_stats.primary_policy_code = 
cpu_to_be32(acm_bin_pol.primary_policy_code);
+    acm_stats.secondary_policy_code = 
cpu_to_be32(acm_bin_pol.secondary_policy_code);
+    acm_stats.primary_stats_offset = cpu_to_be32(sizeof(struct 
acm_stats_buffer));
+    acm_stats.secondary_stats_offset = cpu_to_be32(sizeof(struct 
acm_stats_buffer) + len1);
+    acm_stats.len = cpu_to_be32(sizeof(struct acm_stats_buffer) + len1 + len2);
 
     memcpy(stats_buffer, &acm_stats, sizeof(struct acm_stats_buffer));
 
diff -r 99d36a153024 -r 21d6135f522f xen/acm/acm_simple_type_enforcement_hooks.c
--- a/xen/acm/acm_simple_type_enforcement_hooks.c       Mon Jan 29 16:49:29 
2007 +0000
+++ b/xen/acm/acm_simple_type_enforcement_hooks.c       Mon Jan 29 16:50:22 
2007 +0000
@@ -143,11 +143,11 @@ ste_dump_policy(u8 *buf, u32 buf_size) {
     if (buf_size < sizeof(struct acm_ste_policy_buffer))
         return -EINVAL;
 
-    ste_buf->ste_max_types = htonl(ste_bin_pol.max_types);
-    ste_buf->ste_max_ssidrefs = htonl(ste_bin_pol.max_ssidrefs);
-    ste_buf->policy_code = htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
-    ste_buf->ste_ssid_offset = htonl(sizeof(struct acm_ste_policy_buffer));
-    ret = ntohl(ste_buf->ste_ssid_offset) +
+    ste_buf->ste_max_types = cpu_to_be32(ste_bin_pol.max_types);
+    ste_buf->ste_max_ssidrefs = cpu_to_be32(ste_bin_pol.max_ssidrefs);
+    ste_buf->policy_code = cpu_to_be32(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
+    ste_buf->ste_ssid_offset = cpu_to_be32(sizeof(struct 
acm_ste_policy_buffer));
+    ret = be32_to_cpu(ste_buf->ste_ssid_offset) +
         sizeof(domaintype_t)*ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types;
 
     ret = (ret + 7) & ~7;
@@ -156,7 +156,7 @@ ste_dump_policy(u8 *buf, u32 buf_size) {
         return -EINVAL;
 
     /* now copy buffer over */
-    arrcpy(buf + ntohl(ste_buf->ste_ssid_offset),
+    arrcpy(buf + be32_to_cpu(ste_buf->ste_ssid_offset),
            ste_bin_pol.ssidrefs,
            sizeof(domaintype_t),
            ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types);
@@ -287,11 +287,11 @@ ste_set_policy(u8 *buf, u32 buf_size)
         return -EINVAL;
 
     /* Convert endianess of policy */
-    ste_buf->policy_code = ntohl(ste_buf->policy_code);
-    ste_buf->policy_version = ntohl(ste_buf->policy_version);
-    ste_buf->ste_max_types = ntohl(ste_buf->ste_max_types);
-    ste_buf->ste_max_ssidrefs = ntohl(ste_buf->ste_max_ssidrefs);
-    ste_buf->ste_ssid_offset = ntohl(ste_buf->ste_ssid_offset);
+    ste_buf->policy_code = be32_to_cpu(ste_buf->policy_code);
+    ste_buf->policy_version = be32_to_cpu(ste_buf->policy_version);
+    ste_buf->ste_max_types = be32_to_cpu(ste_buf->ste_max_types);
+    ste_buf->ste_max_ssidrefs = be32_to_cpu(ste_buf->ste_max_ssidrefs);
+    ste_buf->ste_ssid_offset = be32_to_cpu(ste_buf->ste_ssid_offset);
 
     /* policy type and version checks */
     if ((ste_buf->policy_code != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) ||
@@ -348,12 +348,12 @@ ste_dump_stats(u8 *buf, u16 buf_len)
     struct acm_ste_stats_buffer stats;
 
     /* now send the hook counts to user space */
-    stats.ec_eval_count = htonl(atomic_read(&ste_bin_pol.ec_eval_count));
-    stats.gt_eval_count = htonl(atomic_read(&ste_bin_pol.gt_eval_count));
-    stats.ec_denied_count = htonl(atomic_read(&ste_bin_pol.ec_denied_count));
-    stats.gt_denied_count = htonl(atomic_read(&ste_bin_pol.gt_denied_count));
-    stats.ec_cachehit_count = 
htonl(atomic_read(&ste_bin_pol.ec_cachehit_count));
-    stats.gt_cachehit_count = 
htonl(atomic_read(&ste_bin_pol.gt_cachehit_count));
+    stats.ec_eval_count = cpu_to_be32(atomic_read(&ste_bin_pol.ec_eval_count));
+    stats.gt_eval_count = cpu_to_be32(atomic_read(&ste_bin_pol.gt_eval_count));
+    stats.ec_denied_count = 
cpu_to_be32(atomic_read(&ste_bin_pol.ec_denied_count));
+    stats.gt_denied_count = 
cpu_to_be32(atomic_read(&ste_bin_pol.gt_denied_count));
+    stats.ec_cachehit_count = 
cpu_to_be32(atomic_read(&ste_bin_pol.ec_cachehit_count));
+    stats.gt_cachehit_count = 
cpu_to_be32(atomic_read(&ste_bin_pol.gt_cachehit_count));
 
     if (buf_len < sizeof(struct acm_ste_stats_buffer))
         return -ENOMEM;
diff -r 99d36a153024 -r 21d6135f522f xen/arch/ia64/linux-xen/setup.c
--- a/xen/arch/ia64/linux-xen/setup.c   Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/ia64/linux-xen/setup.c   Mon Jan 29 16:50:22 2007 +0000
@@ -424,8 +424,7 @@ setup_arch (char **cmdline_p)
                        else
                                len = strlen (mvec_name);
                        len = min(len, sizeof (str) - 1);
-                       strncpy (str, mvec_name, len);
-                       str[len] = '\0';
+                       strlcpy (str, mvec_name, len);
                        mvec_name = str;
                } else
                        mvec_name = acpi_get_sysname();
@@ -564,7 +563,7 @@ show_cpuinfo (struct seq_file *m, void *
                                *cp++ = sep;
                        sep = ',';
                        *cp++ = ' ';
-                       strcpy(cp, feature_bits[i].feature_name);
+                       strlcpy(cp, feature_bits[i].feature_name, 
sizeof(features));
                        cp += strlen(feature_bits[i].feature_name);
                        mask &= ~feature_bits[i].mask;
                }
diff -r 99d36a153024 -r 21d6135f522f xen/arch/ia64/xen/dom_fw.c
--- a/xen/arch/ia64/xen/dom_fw.c        Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/ia64/xen/dom_fw.c        Mon Jan 29 16:50:22 2007 +0000
@@ -333,13 +333,13 @@ dom_fw_fake_acpi(struct domain *d, struc
        memset(tables, 0, sizeof(struct fake_acpi_tables));
 
        /* setup XSDT (64bit version of RSDT) */
-       strncpy(xsdt->signature, XSDT_SIG, 4);
+       strlcpy(xsdt->signature, XSDT_SIG, sizeof(xsdt->signature));
        /* XSDT points to both the FADT and the MADT, so add one entry */
        xsdt->length = sizeof(struct xsdt_descriptor_rev2) + sizeof(u64);
        xsdt->revision = 1;
-       strcpy(xsdt->oem_id, "XEN");
-       strcpy(xsdt->oem_table_id, "Xen/ia64");
-       strcpy(xsdt->asl_compiler_id, "XEN");
+       strlcpy(xsdt->oem_id, "XEN", sizeof(xsdt->oem_id));
+       strlcpy(xsdt->oem_table_id, "Xen/ia64", sizeof(xsdt->oem_table_id));
+       strlcpy(xsdt->asl_compiler_id, "XEN", sizeof(xsdt->asl_compiler_id));
        xsdt->asl_compiler_revision = (xen_major_version() << 16) |
                xen_minor_version();
 
@@ -349,16 +349,16 @@ dom_fw_fake_acpi(struct domain *d, struc
        xsdt->checksum = generate_acpi_checksum(xsdt, xsdt->length);
 
        /* setup FADT */
-       strncpy(fadt->signature, FADT_SIG, 4);
+       strlcpy(fadt->signature, FADT_SIG, sizeof(fadt->signature));
        fadt->length = sizeof(struct fadt_descriptor_rev2);
        fadt->revision = FADT2_REVISION_ID;
-       strcpy(fadt->oem_id, "XEN");
-       strcpy(fadt->oem_table_id, "Xen/ia64");
-       strcpy(fadt->asl_compiler_id, "XEN");
+       strlcpy(fadt->oem_id, "XEN", sizeof(fadt->oem_id));
+       strlcpy(fadt->oem_table_id, "Xen/ia64", sizeof(fadt->oem_table_id));
+       strlcpy(fadt->asl_compiler_id, "XEN", sizeof(fadt->asl_compiler_id));
        fadt->asl_compiler_revision = (xen_major_version() << 16) |
                xen_minor_version();
 
-       strncpy(facs->signature, FACS_SIG, 4);
+       strlcpy(facs->signature, FACS_SIG, sizeof(facs->signature));
        facs->version = 1;
        facs->length = sizeof(struct facs_descriptor_rev2);
 
@@ -386,8 +386,8 @@ dom_fw_fake_acpi(struct domain *d, struc
        fadt->checksum = generate_acpi_checksum(fadt, fadt->length);
 
        /* setup RSDP */
-       strncpy(rsdp->signature, RSDP_SIG, 8);
-       strcpy(rsdp->oem_id, "XEN");
+       strlcpy(rsdp->signature, RSDP_SIG, sizeof(rsdp->signature));
+       strlcpy(rsdp->oem_id, "XEN", sizeof(rsdp->oem_id));
        rsdp->revision = 2; /* ACPI 2.0 includes XSDT */
        rsdp->length = sizeof(struct acpi20_table_rsdp);
        rsdp->xsdt_address = ACPI_TABLE_MPA(xsdt);
@@ -397,11 +397,11 @@ dom_fw_fake_acpi(struct domain *d, struc
        rsdp->ext_checksum = generate_acpi_checksum(rsdp, rsdp->length);
 
        /* setup DSDT with trivial namespace. */ 
-       strncpy(dsdt->signature, DSDT_SIG, 4);
+       strlcpy(dsdt->signature, DSDT_SIG, sizeof(dsdt->signature));
        dsdt->revision = 1;
-       strcpy(dsdt->oem_id, "XEN");
-       strcpy(dsdt->oem_table_id, "Xen/ia64");
-       strcpy(dsdt->asl_compiler_id, "XEN");
+       strlcpy(dsdt->oem_id, "XEN", sizeof(dsdt->oem_id));
+       strlcpy(dsdt->oem_table_id, "Xen/ia64", sizeof(dsdt->oem_table_id));
+       strlcpy(dsdt->asl_compiler_id, "XEN", sizeof(dsdt->asl_compiler_id));
        dsdt->asl_compiler_revision = (xen_major_version() << 16) |
                xen_minor_version();
 
@@ -409,7 +409,7 @@ dom_fw_fake_acpi(struct domain *d, struc
        tables->aml[0] = 0x10; /* Scope */
        tables->aml[1] = 0x40; /* length/offset to next object (patched) */
        tables->aml[2] = 0x00;
-       strncpy((char *)&tables->aml[3], "_SB_", 4);
+       strlcpy((char *)&tables->aml[3], "_SB_", 5);
 
        /* The processor object isn't absolutely necessary, revist for SMP */
        aml_len = 7;
@@ -437,11 +437,14 @@ dom_fw_fake_acpi(struct domain *d, struc
        dsdt->checksum = generate_acpi_checksum(dsdt, dsdt->length);
 
        /* setup MADT */
-       strncpy(madt->header.signature, APIC_SIG, 4);
+       strlcpy(madt->header.signature, APIC_SIG, 
sizeof(madt->header.signature));
        madt->header.revision = 2;
-       strcpy(madt->header.oem_id, "XEN");
-       strcpy(madt->header.oem_table_id, "Xen/ia64");
-       strcpy(madt->header.asl_compiler_id, "XEN");
+       strlcpy(madt->header.oem_id, "XEN",
+               sizeof(madt->header.oem_id));
+       strlcpy(madt->header.oem_table_id, "Xen/ia64",
+               sizeof(madt->header.oem_table_id));
+       strlcpy(madt->header.asl_compiler_id, "XEN",
+               sizeof(madt->header.asl_compiler_id));
        madt->header.asl_compiler_revision = (xen_major_version() << 16) |
                xen_minor_version();
 
@@ -760,8 +763,10 @@ dom_fw_init(struct domain *d,
        tables->sal_systab.sal_rev_major = 0;
        tables->sal_systab.entry_count = 2;
 
-       strcpy((char *)tables->sal_systab.oem_id, "Xen/ia64");
-       strcpy((char *)tables->sal_systab.product_id, "Xen/ia64");
+       strlcpy((char *)tables->sal_systab.oem_id, "Xen/ia64",
+               sizeof(tables->sal_systab.oem_id));
+       strlcpy((char *)tables->sal_systab.product_id, "Xen/ia64",
+               sizeof(tables->sal_systab.product_id));
 
        /* PAL entry point: */
        tables->sal_ed.type = SAL_DESC_ENTRY_POINT;
diff -r 99d36a153024 -r 21d6135f522f xen/arch/ia64/xen/domain.c
--- a/xen/arch/ia64/xen/domain.c        Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/ia64/xen/domain.c        Mon Jan 29 16:50:22 2007 +0000
@@ -1148,8 +1148,7 @@ int construct_dom0(struct domain *d,
        dom_fw_setup(d, bp_mpa, max_pages * PAGE_SIZE);
 
        /* Fill boot param.  */
-       strncpy((char *)si->cmd_line, dom0_command_line, sizeof(si->cmd_line));
-       si->cmd_line[sizeof(si->cmd_line)-1] = 0;
+       strlcpy((char *)si->cmd_line, dom0_command_line, sizeof(si->cmd_line));
 
        bp = (struct ia64_boot_param *)((unsigned char *)si +
                                        sizeof(start_info_t));
diff -r 99d36a153024 -r 21d6135f522f xen/arch/ia64/xen/gdbstub.c
--- a/xen/arch/ia64/xen/gdbstub.c       Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/ia64/xen/gdbstub.c       Mon Jan 29 16:50:22 2007 +0000
@@ -639,7 +639,7 @@ kgdb_get_reg(int regnum, struct unw_fram
                outbuffer[size*2] = 0;
        }
        else
-               strcpy(outbuffer, "E0");
+               strlcpy(outbuffer, "E0", sizeof("E0"));
 
        return;
 #else
diff -r 99d36a153024 -r 21d6135f522f xen/arch/ia64/xen/oprofile/perfmon.c
--- a/xen/arch/ia64/xen/oprofile/perfmon.c      Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/ia64/xen/oprofile/perfmon.c      Mon Jan 29 16:50:22 2007 +0000
@@ -119,7 +119,7 @@ xenoprof_arch_init(int *num_events, int 
 xenoprof_arch_init(int *num_events, int *is_primary, char *cpu_type)
 {
     *num_events = 0;
-    strncpy(cpu_type, get_cpu_type(), XENOPROF_CPU_TYPE_SIZE - 1);
+    strlcpy(cpu_type, get_cpu_type(), XENOPROF_CPU_TYPE_SIZE);
     cpu_type[XENOPROF_CPU_TYPE_SIZE - 1] = '\0';
 
     *is_primary = 0;
diff -r 99d36a153024 -r 21d6135f522f xen/arch/powerpc/domain_build.c
--- a/xen/arch/powerpc/domain_build.c   Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/powerpc/domain_build.c   Mon Jan 29 16:50:22 2007 +0000
@@ -290,7 +290,7 @@ int construct_dom0(struct domain *d,
 
     memset(si->cmd_line, 0, sizeof(si->cmd_line));
     if ( cmdline != NULL )
-        strncpy((char *)si->cmd_line, cmdline, sizeof(si->cmd_line)-1);
+        strlcpy((char *)si->cmd_line, cmdline, sizeof(si->cmd_line));
 
     v->arch.ctxt.msr = msr;
     v->arch.ctxt.pc = pc;
diff -r 99d36a153024 -r 21d6135f522f xen/arch/powerpc/of-devtree.c
--- a/xen/arch/powerpc/of-devtree.c     Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/powerpc/of-devtree.c     Mon Jan 29 16:50:22 2007 +0000
@@ -358,8 +358,7 @@ static ofdn_t ofd_node_create(
     n->on_io = 0;
     n->on_pathlen = pathlen;
     n->on_last = ofd_pathsplit_left(path, '/', pathlen);
-    strncpy(n->on_path, path, pathlen);
-    n->on_path[n->on_pathlen] = 0;
+    strlcpy(n->on_path, path, pathlen);
 
     return pos;
 }
diff -r 99d36a153024 -r 21d6135f522f xen/arch/powerpc/ofd_fixup.c
--- a/xen/arch/powerpc/ofd_fixup.c      Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/powerpc/ofd_fixup.c      Mon Jan 29 16:50:22 2007 +0000
@@ -267,7 +267,7 @@ static ofdn_t ofd_chosen_props(void *m, 
                      &path[1], sizeof (path) - 1);
     }
 
-    strcpy(bootargs, cmdline);
+    strlcpy(bootargs, cmdline, sizeof(bootargs));
     bsz = strlen(bootargs) + 1;
     rm = sizeof (bootargs) - bsz;
 
diff -r 99d36a153024 -r 21d6135f522f xen/arch/x86/cpu/common.c
--- a/xen/arch/x86/cpu/common.c Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/x86/cpu/common.c Mon Jan 29 16:50:22 2007 +0000
@@ -30,9 +30,9 @@ static void default_init(struct cpuinfo_
        if (c->cpuid_level == -1) {
                /* No cpuid. It must be an ancient CPU */
                if (c->x86 == 4)
-                       strcpy(c->x86_model_id, "486");
+                       safe_strcpy(c->x86_model_id, "486");
                else if (c->x86 == 3)
-                       strcpy(c->x86_model_id, "386");
+                       safe_strcpy(c->x86_model_id, "386");
        }
 }
 
@@ -383,7 +383,7 @@ void __devinit identify_cpu(struct cpuin
                char *p;
                p = table_lookup_model(c);
                if ( p )
-                       strcpy(c->x86_model_id, p);
+                       safe_strcpy(c->x86_model_id, p);
                else
                        /* Last resort... */
                        snprintf(c->x86_model_id, sizeof(c->x86_model_id),
diff -r 99d36a153024 -r 21d6135f522f xen/arch/x86/cpu/cyrix.c
--- a/xen/arch/x86/cpu/cyrix.c  Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/x86/cpu/cyrix.c  Mon Jan 29 16:50:22 2007 +0000
@@ -181,7 +181,6 @@ static void __init init_cyrix(struct cpu
 static void __init init_cyrix(struct cpuinfo_x86 *c)
 {
        unsigned char dir0, dir0_msn, dir0_lsn, dir1 = 0;
-       char *buf = c->x86_model_id;
        const char *p = NULL;
 
        /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
@@ -302,8 +301,8 @@ static void __init init_cyrix(struct cpu
                dir0_msn = 7;
                break;
        }
-       strcpy(buf, Cx86_model[dir0_msn & 7]);
-       if (p) strcat(buf, p);
+       safe_strcpy(c->x86_model_id, Cx86_model[dir0_msn & 7]);
+       if (p) safe_strcat(c->x86_model_id, p);
        return;
 }
 
@@ -339,7 +338,7 @@ static void cyrix_identify(struct cpuinf
        if ( c->x86 == 4 && test_cyrix_52div() ) {
                unsigned char dir0, dir1;
                
-               strcpy(c->x86_vendor_id, "CyrixInstead");
+               safe_strcpy(c->x86_vendor_id, "CyrixInstead");
                c->x86_vendor = X86_VENDOR_CYRIX;
                
                /* Actually enable cpuid on the older cyrix */
diff -r 99d36a153024 -r 21d6135f522f xen/arch/x86/cpu/intel.c
--- a/xen/arch/x86/cpu/intel.c  Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/x86/cpu/intel.c  Mon Jan 29 16:50:22 2007 +0000
@@ -152,7 +152,7 @@ static void __devinit init_intel(struct 
        }
 
        if ( p )
-               strcpy(c->x86_model_id, p);
+               safe_strcpy(c->x86_model_id, p);
        
        c->x86_max_cores = num_cpu_cores(c);
 
diff -r 99d36a153024 -r 21d6135f522f xen/arch/x86/dmi_scan.c
--- a/xen/arch/x86/dmi_scan.c   Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/x86/dmi_scan.c   Mon Jan 29 16:50:22 2007 +0000
@@ -159,7 +159,7 @@ static void __init dmi_save_ident(struct
                return;
        dmi_ident[slot] = alloc_bootmem(strlen(p)+1);
        if(dmi_ident[slot])
-               strcpy(dmi_ident[slot], p);
+               safe_strcpy(dmi_ident[slot], p);
        else
                printk(KERN_ERR "dmi_save_ident: out of memory.\n");
 }
diff -r 99d36a153024 -r 21d6135f522f xen/arch/x86/domain_build.c
--- a/xen/arch/x86/domain_build.c       Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/x86/domain_build.c       Mon Jan 29 16:50:22 2007 +0000
@@ -871,7 +871,7 @@ int construct_dom0(struct domain *d,
 
     memset(si->cmd_line, 0, sizeof(si->cmd_line));
     if ( cmdline != NULL )
-        strlcpy((char *)si->cmd_line, cmdline, sizeof(si->cmd_line));
+        safe_strcpy(si->cmd_line, cmdline);
 
     if ( fill_console_start_info((void *)(si + 1)) )
     {
diff -r 99d36a153024 -r 21d6135f522f xen/arch/x86/hvm/intercept.c
--- a/xen/arch/x86/hvm/intercept.c      Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/x86/hvm/intercept.c      Mon Jan 29 16:50:22 2007 +0000
@@ -173,7 +173,7 @@ int hvm_register_savevm(struct domain *d
         return -1;
     }
 
-    strlcpy(se->idstr, idstr, HVM_SE_IDSTR_LEN);
+    safe_strcpy(se->idstr, idstr);
 
     se->instance_id = instance_id;
     se->version_id = version_id;
@@ -217,7 +217,7 @@ int hvm_save(struct domain *d, hvm_domai
 
     for(se = d->arch.hvm_domain.first_se; se != NULL; se = se->next) {
         /* ID string */
-        len = strnlen(se->idstr, HVM_SE_IDSTR_LEN);
+        len = strnlen(se->idstr, sizeof(se->idstr));
         hvm_put_8u(h, len);
         hvm_put_buffer(h, se->idstr, len);
 
@@ -255,7 +255,7 @@ static HVMStateEntry *find_se(struct dom
     HVMStateEntry *se;
 
     for(se = d->arch.hvm_domain.first_se; se != NULL; se = se->next) {
-        if (!strncmp(se->idstr, idstr, HVM_SE_IDSTR_LEN) &&
+        if (!strncmp(se->idstr, idstr, sizeof(se->idstr)) &&
             instance_id == se->instance_id){
             return se;
         }
diff -r 99d36a153024 -r 21d6135f522f xen/arch/x86/setup.c
--- a/xen/arch/x86/setup.c      Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/arch/x86/setup.c      Mon Jan 29 16:50:22 2007 +0000
@@ -111,7 +111,7 @@ static void parse_acpi_param(char *s)
 static void parse_acpi_param(char *s)
 {
     /* Save the parameter so it can be propagated to domain0. */
-    strlcpy(acpi_param, s, sizeof(acpi_param));
+    safe_strcpy(acpi_param, s);
 
     /* Interpret the parameter for use within Xen. */
     if ( !strcmp(s, "off") )
@@ -748,22 +748,22 @@ void __init __start_xen(multiboot_info_t
         if ( (cmdline = strchr(cmdline, ' ')) != NULL )
         {
             while ( *cmdline == ' ' ) cmdline++;
-            strcpy(dom0_cmdline, cmdline);
+            safe_strcpy(dom0_cmdline, cmdline);
+        }
+
+        /* Append any extra parameters. */
+        if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") )
+            safe_strcat(dom0_cmdline, " noapic");
+        if ( acpi_skip_timer_override &&
+             !strstr(dom0_cmdline, "acpi_skip_timer_override") )
+            safe_strcat(dom0_cmdline, " acpi_skip_timer_override");
+        if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") )
+        {
+            safe_strcat(dom0_cmdline, " acpi=");
+            safe_strcat(dom0_cmdline, acpi_param);
         }
 
         cmdline = dom0_cmdline;
-
-        /* Append any extra parameters. */
-        if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
-            strcat(cmdline, " noapic");
-        if ( acpi_skip_timer_override &&
-             !strstr(cmdline, "acpi_skip_timer_override") )
-            strcat(cmdline, " acpi_skip_timer_override");
-        if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") )
-        {
-            strcat(cmdline, " acpi=");
-            strcat(cmdline, acpi_param);
-        }
     }
 
     if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) )
diff -r 99d36a153024 -r 21d6135f522f xen/common/kexec.c
--- a/xen/common/kexec.c        Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/common/kexec.c        Mon Jan 29 16:50:22 2007 +0000
@@ -131,7 +131,7 @@ __initcall(register_crashdump_trigger);
 
 static void setup_note(Elf_Note *n, const char *name, int type, int descsz)
 {
-    strcpy(ELFNOTE_NAME(n), name);
+    safe_strcpy(ELFNOTE_NAME(n), name);
     n->namesz = strlen(name);
     n->descsz = descsz;
     n->type = type;
diff -r 99d36a153024 -r 21d6135f522f xen/common/keyhandler.c
--- a/xen/common/keyhandler.c   Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/common/keyhandler.c   Mon Jan 29 16:50:22 2007 +0000
@@ -67,8 +67,7 @@ void register_keyhandler(
     ASSERT(key_table[key].u.handler == NULL);
     key_table[key].u.handler = handler;
     key_table[key].flags     = 0;
-    strlcpy(key_table[key].desc, desc, STR_MAX);
-    key_table[key].desc[STR_MAX-1] = '\0';
+    safe_strcpy(key_table[key].desc, desc);
 }
 
 void register_irq_keyhandler(
@@ -77,7 +76,7 @@ void register_irq_keyhandler(
     ASSERT(key_table[key].u.irq_handler == NULL);
     key_table[key].u.irq_handler = handler;
     key_table[key].flags         = KEYHANDLER_IRQ_CALLBACK;
-    strlcpy(key_table[key].desc, desc, STR_MAX);
+    safe_strcpy(key_table[key].desc, desc);
 }
 
 static void show_handlers(unsigned char key)
diff -r 99d36a153024 -r 21d6135f522f xen/common/libelf/libelf-dominfo.c
--- a/xen/common/libelf/libelf-dominfo.c        Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/common/libelf/libelf-dominfo.c        Mon Jan 29 16:50:22 2007 +0000
@@ -128,16 +128,16 @@ int elf_xen_parse_note(struct elf_binary
     switch (type)
     {
     case XEN_ELFNOTE_LOADER:
-       elf_strlcpy(parms->loader, str, sizeof(parms->loader));
+       safe_strcpy(parms->loader, str);
        break;
     case XEN_ELFNOTE_GUEST_OS:
-       elf_strlcpy(parms->guest_os, str, sizeof(parms->guest_os));
+       safe_strcpy(parms->guest_os, str);
        break;
     case XEN_ELFNOTE_GUEST_VERSION:
-       elf_strlcpy(parms->guest_ver, str, sizeof(parms->guest_ver));
+       safe_strcpy(parms->guest_ver, str);
        break;
     case XEN_ELFNOTE_XEN_VERSION:
-       elf_strlcpy(parms->xen_ver, str, sizeof(parms->xen_ver));
+       safe_strcpy(parms->xen_ver, str);
        break;
     case XEN_ELFNOTE_PAE_MODE:
        if (0 == strcmp(str, "yes"))
@@ -224,13 +224,13 @@ int elf_xen_parse_guest_info(struct elf_
 
        /* strings */
        if (0 == strcmp(name, "LOADER"))
-           elf_strlcpy(parms->loader, value, sizeof(parms->loader));
+           safe_strcpy(parms->loader, value);
        if (0 == strcmp(name, "GUEST_OS"))
-           elf_strlcpy(parms->guest_os, value, sizeof(parms->guest_os));
+           safe_strcpy(parms->guest_os, value);
        if (0 == strcmp(name, "GUEST_VER"))
-           elf_strlcpy(parms->guest_ver, value, sizeof(parms->guest_ver));
+           safe_strcpy(parms->guest_ver, value);
        if (0 == strcmp(name, "XEN_VER"))
-           elf_strlcpy(parms->xen_ver, value, sizeof(parms->xen_ver));
+           safe_strcpy(parms->xen_ver, value);
        if (0 == strcmp(name, "PAE"))
        {
            if (0 == strcmp(value, "yes[extended-cr3]"))
diff -r 99d36a153024 -r 21d6135f522f xen/common/libelf/libelf-private.h
--- a/xen/common/libelf/libelf-private.h        Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/common/libelf/libelf-private.h        Mon Jan 29 16:50:22 2007 +0000
@@ -20,8 +20,6 @@
 #define bswap_16(x) swab16(x)
 #define bswap_32(x) swab32(x)
 #define bswap_64(x) swab64(x)
-
-#define elf_strlcpy(d,s,c) strlcpy(d,s,c)
 
 #else /* !__XEN__ */
 
@@ -52,13 +50,10 @@
         xc_set_error(XC_INVALID_KERNEL, fmt , ## args );  \
        } while (0)
 
-/* SysV unices have no strlcpy/strlcat. */
-static inline size_t elf_strlcpy(char *dest, const char *src, size_t size)
-{
-    strncpy(dest, src, size-1);
-    dest[size-1] = '\0';
-    return strlen(src);
-}
+#define safe_strcpy(d,s)                        \
+do { strncpy((d),(s),sizeof((d))-1);            \
+     (d)[sizeof((d))-1] = '\0';                 \
+} while (0)
 
 #endif
 
diff -r 99d36a153024 -r 21d6135f522f xen/common/perfc.c
--- a/xen/common/perfc.c        Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/common/perfc.c        Mon Jan 29 16:50:22 2007 +0000
@@ -148,8 +148,7 @@ static int perfc_copy_info(XEN_GUEST_HAN
     {
         for ( i = 0; i < NR_PERFCTRS; i++ )
         {
-            strlcpy(perfc_d[i].name, perfc_info[i].name,
-                    sizeof(perfc_d[i].name));
+            safe_strcpy(perfc_d[i].name, perfc_info[i].name);
 
             switch ( perfc_info[i].type )
             {
diff -r 99d36a153024 -r 21d6135f522f xen/common/rangeset.c
--- a/xen/common/rangeset.c     Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/common/rangeset.c     Mon Jan 29 16:50:22 2007 +0000
@@ -283,7 +283,7 @@ struct rangeset *rangeset_new(
 
     if ( name != NULL )
     {
-        strlcpy(r->name, name, sizeof(r->name));
+        safe_strcpy(r->name, name);
     }
     else
     {
diff -r 99d36a153024 -r 21d6135f522f xen/common/string.c
--- a/xen/common/string.c       Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/common/string.c       Mon Jan 29 16:50:22 2007 +0000
@@ -41,44 +41,6 @@ int strnicmp(const char *s1, const char 
 }
 #endif
 
-#ifndef __HAVE_ARCH_STRCPY
-/**
- * strcpy - Copy a %NUL terminated string
- * @dest: Where to copy the string to
- * @src: Where to copy the string from
- */
-char * strcpy(char * dest,const char *src)
-{
-       char *tmp = dest;
-
-       while ((*dest++ = *src++) != '\0')
-               /* nothing */;
-       return tmp;
-}
-#endif
-
-#ifndef __HAVE_ARCH_STRNCPY
-/**
- * strncpy - Copy a length-limited, %NUL-terminated string
- * @dest: Where to copy the string to
- * @src: Where to copy the string from
- * @count: The maximum number of bytes to copy
- *
- * Note that unlike userspace strncpy, this does not %NUL-pad the buffer.
- * However, the result is not %NUL-terminated if the source exceeds
- * @count bytes.
- */
-char * strncpy(char * dest,const char *src,size_t count)
-{
-       char *tmp = dest;
-
-       while (count-- && (*dest++ = *src++) != '\0')
-               /* nothing */;
-
-       return tmp;
-}
-#endif
-
 #ifndef __HAVE_ARCH_STRLCPY
 /**
  * strlcpy - Copy a %NUL terminated string into a sized buffer
@@ -105,52 +67,33 @@ EXPORT_SYMBOL(strlcpy);
 EXPORT_SYMBOL(strlcpy);
 #endif
 
-#ifndef __HAVE_ARCH_STRCAT
-/**
- * strcat - Append one %NUL-terminated string to another
- * @dest: The string to be appended to
- * @src: The string to append to it
- */
-char * strcat(char * dest, const char * src)
-{
-       char *tmp = dest;
-
-       while (*dest)
-               dest++;
-       while ((*dest++ = *src++) != '\0')
-               ;
-
-       return tmp;
-}
-#endif
-
-#ifndef __HAVE_ARCH_STRNCAT
-/**
- * strncat - Append a length-limited, %NUL-terminated string to another
- * @dest: The string to be appended to
- * @src: The string to append to it
- * @count: The maximum numbers of bytes to copy
- *
- * Note that in contrast to strncpy, strncat ensures the result is
- * terminated.
- */
-char * strncat(char *dest, const char *src, size_t count)
-{
-       char *tmp = dest;
-
-       if (count) {
-               while (*dest)
-                       dest++;
-               while ((*dest++ = *src++)) {
-                       if (--count == 0) {
-                               *dest = '\0';
-                               break;
-                       }
-               }
-       }
-
-       return tmp;
-}
+#ifndef __HAVE_ARCH_STRLCAT
+/**
+ * strlcat - Append a %NUL terminated string into a sized buffer
+ * @dest: Where to copy the string to
+ * @src: Where to copy the string from
+ * @size: size of destination buffer
+ *
+ * Compatible with *BSD: the result is always a valid
+ * NUL-terminated string that fits in the buffer (unless,
+ * of course, the buffer size is zero).
+ */
+size_t strlcat(char *dest, const char *src, size_t size)
+{
+       size_t slen = strlen(src);
+       size_t dlen = strnlen(dest, size);
+       char *p = dest + dlen;
+
+       while ((p - dest) < size)
+               if ((*p++ = *src++) == '\0')
+                       break;
+
+       if (dlen < size)
+               *(p-1) = '\0';
+
+       return slen + dlen;
+}
+EXPORT_SYMBOL(strlcat);
 #endif
 
 #ifndef __HAVE_ARCH_STRCMP
diff -r 99d36a153024 -r 21d6135f522f xen/drivers/char/console.c
--- a/xen/drivers/char/console.c        Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/drivers/char/console.c        Mon Jan 29 16:50:22 2007 +0000
@@ -481,7 +481,7 @@ void printk(const char *fmt, ...)
 
 void set_printk_prefix(const char *prefix)
 {
-    strcpy(printk_prefix, prefix);
+    safe_strcpy(printk_prefix, prefix);
 }
 
 void init_console(void)
@@ -771,7 +771,7 @@ void debugtrace_printk(const char *fmt, 
 
     ASSERT(debugtrace_buf[debugtrace_bytes - 1] == 0);
 
-    sprintf(buf, "%u ", ++count);
+    snprintf(buf, sizeof(buf), "%u ", ++count);
 
     va_start(args, fmt);
     (void)vsnprintf(buf + strlen(buf), sizeof(buf), fmt, args);
diff -r 99d36a153024 -r 21d6135f522f xen/include/acm/acm_endian.h
--- a/xen/include/acm/acm_endian.h      Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/include/acm/acm_endian.h      Mon Jan 29 16:50:22 2007 +0000
@@ -22,57 +22,27 @@
 #ifndef _ACM_ENDIAN_H
 #define _ACM_ENDIAN_H
 
-/* don't use these functions in performance critical sections! */
-
-/* set during initialization by testing */
-extern u8 little_endian;
-
-static inline u32 ntohl(u32 x) 
-{
-    if (little_endian)
-        return 
-            ( (((x) >> 24) & 0xff      )| 
-              (((x) >>  8) & 0xff00    )| 
-              (((x) <<  8) & 0xff0000  )|
-              (((x) << 24) & 0xff000000) );
-    else
-        return x;
-}
-
-static inline u16 ntohs(u16 x) 
-{
-    if (little_endian)
-        return 
-            ( (((x) >> 8) & 0xff   )|
-              (((x) << 8) & 0xff00 ) );
-    else
-        return x;
-}
-
-#define htonl(x) ntohl(x)
-#define htons(x) ntohs(x)
+#include <asm/byteorder.h>
 
 static inline void arrcpy16(u16 *dest, const u16 *src, size_t n)
 {
-    unsigned int i = 0;
-    while (i < n) {
-        dest[i] = htons(src[i]);
-        i++;
-    }
+    unsigned int i;
+    for ( i = 0; i < n; i++ )
+        dest[i] = cpu_to_be16(src[i]);
 }
 
 static inline void arrcpy32(u32 *dest, const u32 *src, size_t n)
 {
-    unsigned int i = 0;
-    while (i < n) {
-        dest[i] = htonl(src[i]);
-        i++;
-    }
+    unsigned int i;
+    for ( i = 0; i < n; i++ )
+        dest[i] = cpu_to_be32(src[i]);
 }
 
-static inline void arrcpy(void *dest, const void *src, unsigned int elsize, 
size_t n)
+static inline void arrcpy(
+    void *dest, const void *src, unsigned int elsize, size_t n)
 {
-    switch (elsize) {
+    switch ( elsize )
+    {
     case sizeof(u16):
         arrcpy16((u16 *)dest, (u16 *)src, n);
         break;
diff -r 99d36a153024 -r 21d6135f522f xen/include/xen/byteorder/big_endian.h
--- a/xen/include/xen/byteorder/big_endian.h    Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/include/xen/byteorder/big_endian.h    Mon Jan 29 16:50:22 2007 +0000
@@ -11,10 +11,6 @@
 #include <xen/types.h>
 #include <xen/byteorder/swab.h>
 
-#define __constant_htonl(x) ((__force __be32)(__u32)(x))
-#define __constant_ntohl(x) ((__force __u32)(__be32)(x))
-#define __constant_htons(x) ((__force __be16)(__u16)(x))
-#define __constant_ntohs(x) ((__force __u16)(__be16)(x))
 #define __constant_cpu_to_le64(x) ((__force __le64)___constant_swab64((x)))
 #define __constant_le64_to_cpu(x) ___constant_swab64((__force 
__u64)(__le64)(x))
 #define __constant_cpu_to_le32(x) ((__force __le32)___constant_swab32((x)))
diff -r 99d36a153024 -r 21d6135f522f xen/include/xen/byteorder/little_endian.h
--- a/xen/include/xen/byteorder/little_endian.h Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/include/xen/byteorder/little_endian.h Mon Jan 29 16:50:22 2007 +0000
@@ -11,10 +11,6 @@
 #include <xen/types.h>
 #include <xen/byteorder/swab.h>
 
-#define __constant_htonl(x) ((__force __be32)___constant_swab32((x)))
-#define __constant_ntohl(x) ___constant_swab32((__force __be32)(x))
-#define __constant_htons(x) ((__force __be16)___constant_swab16((x)))
-#define __constant_ntohs(x) ___constant_swab16((__force __be16)(x))
 #define __constant_cpu_to_le64(x) ((__force __le64)(__u64)(x))
 #define __constant_le64_to_cpu(x) ((__force __u64)(__le64)(x))
 #define __constant_cpu_to_le32(x) ((__force __le32)(__u32)(x))
diff -r 99d36a153024 -r 21d6135f522f xen/include/xen/string.h
--- a/xen/include/xen/string.h  Mon Jan 29 16:49:29 2007 +0000
+++ b/xen/include/xen/string.h  Mon Jan 29 16:50:22 2007 +0000
@@ -19,20 +19,20 @@ extern __kernel_size_t strspn(const char
  */
 #include <asm/string.h>
 
-#ifndef __HAVE_ARCH_STRCPY
-extern char * strcpy(char *,const char *);
-#endif
-#ifndef __HAVE_ARCH_STRNCPY
-extern char * strncpy(char *,const char *, __kernel_size_t);
-#endif
+/*
+ * These string functions are considered too dangerous for normal use.
+ * Use safe_strcpy(), safe_strcat(), strlcpy(), strlcat() as appropriate.
+ */
+#define strcpy  __xen_has_no_strcpy__
+#define strcat  __xen_has_no_strcat__
+#define strncpy __xen_has_no_strncpy__
+#define strncat __xen_has_no_strncat__
+
 #ifndef __HAVE_ARCH_STRLCPY
 extern size_t strlcpy(char *,const char *, __kernel_size_t);
 #endif
-#ifndef __HAVE_ARCH_STRCAT
-extern char * strcat(char *, const char *);
-#endif
-#ifndef __HAVE_ARCH_STRNCAT
-extern char * strncat(char *, const char *, __kernel_size_t);
+#ifndef __HAVE_ARCH_STRLCAT
+extern size_t strlcat(char *,const char *, __kernel_size_t);
 #endif
 #ifndef __HAVE_ARCH_STRCMP
 extern int strcmp(const char *,const char *);
@@ -82,9 +82,8 @@ extern void * memchr(const void *,int,__
 }
 #endif
 
-#define safe_strcpy(d,s)                        \
-do { strncpy((d),(s),sizeof((d)));              \
-     (d)[sizeof((d))-1] = '\0';                 \
-} while (0)
+/* safe_xxx always NUL-terminates and returns !=0 if result is truncated. */
+#define safe_strcpy(d, s) (strlcpy(d, s, sizeof(d)) >= sizeof(d))
+#define safe_strcat(d, s) (strlcat(d, s, sizeof(d)) >= sizeof(d))
 
 #endif /* _LINUX_STRING_H_ */

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.