]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/fs/ext2.c (grub_ext2_read_symlink): Use memcpy rather
authorVladimir Serbinenko <phcoder@gmail.com>
Fri, 1 Nov 2013 17:44:46 +0000 (18:44 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Fri, 1 Nov 2013 17:44:46 +0000 (18:44 +0100)
strncpy.
* grub-core/fs/jfs.c (grub_jfs_lookup_symlink): Likewise.
* grub-core/kern/misc.c (grub_strncpy): Move from here ...
* include/grub/misc.h (grub_strncpy): ... to here. Make inline.
* grub-core/net/net.c (grub_net_addr_to_str): Use COMPILE_TIME_ASSERT
+ strcpy rather than strncpy.

ChangeLog
grub-core/fs/ext2.c
grub-core/fs/jfs.c
grub-core/kern/misc.c
grub-core/net/net.c
include/grub/misc.h

index f9305a11ecc2e166694960ef5354a4067f37d629..8b67a496aa1c3b3d927ac778d0f3b970c8c5bf61 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2013-11-01  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * grub-core/fs/ext2.c (grub_ext2_read_symlink): Use memcpy rather
+       strncpy.
+       * grub-core/fs/jfs.c (grub_jfs_lookup_symlink): Likewise.
+       * grub-core/kern/misc.c (grub_strncpy): Move from here ...
+       * include/grub/misc.h (grub_strncpy): ... to here. Make inline.
+       * grub-core/net/net.c (grub_net_addr_to_str): Use COMPILE_TIME_ASSERT
+       + strcpy rather than strncpy.
+
 2013-11-01  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/fs/zfs/zfs.c (nvpair_name): Use correct type for size.
index 46fb76f55b12d0080333c9af3505d989b615cd5b..6941ef2750cc62103aa62fb773a08c36584415a8 100644 (file)
@@ -670,10 +670,10 @@ grub_ext2_read_symlink (grub_fshelp_node_t node)
   /* If the filesize of the symlink is bigger than
      60 the symlink is stored in a separate block,
      otherwise it is stored in the inode.  */
-  if (grub_le_to_cpu32 (diro->inode.size) <= 60)
-    grub_strncpy (symlink,
-                 diro->inode.symlink,
-                 grub_le_to_cpu32 (diro->inode.size));
+  if (grub_le_to_cpu32 (diro->inode.size) <= sizeof (diro->inode.symlink))
+    grub_memcpy (symlink,
+                diro->inode.symlink,
+                grub_le_to_cpu32 (diro->inode.size));
   else
     {
       grub_ext2_read_file (diro, 0, 0, 0,
index 26d77164716b76c1f3723fa3e016e7daf45c3b98..06250149221a4a79a4ade3634fc0d8c03fa64d65 100644 (file)
@@ -723,7 +723,7 @@ grub_jfs_lookup_symlink (struct grub_jfs_data *data, grub_uint32_t ino)
   if (!symlink)
     return grub_errno;
   if (size <= sizeof (data->currinode.symlink.path))
-    grub_strncpy (symlink, (char *) (data->currinode.symlink.path), size);
+    grub_memcpy (symlink, (char *) (data->currinode.symlink.path), size);
   else if (grub_jfs_read_file (data, 0, 0, 0, size, symlink) < 0)
     {
       grub_free (symlink);
index d8de0bb0972d7321f9e11ac8081e4ce4c8ea5f5a..6619c9970fdff4ec4c2364184725ea55f6941520 100644 (file)
@@ -94,17 +94,6 @@ grub_strcpy (char *dest, const char *src)
   return dest;
 }
 
-char *
-grub_strncpy (char *dest, const char *src, int c)
-{
-  char *p = dest;
-
-  while ((*p++ = *src++) != '\0' && --c)
-    ;
-
-  return dest;
-}
-
 int
 grub_printf (const char *fmt, ...)
 {
index 6d143fb51777159318ffde5ca95ecd9a1ef347a9..5f60b0722f7361563aab2ec68ad8bbbfabc3ed3a 100644 (file)
@@ -734,8 +734,8 @@ grub_net_addr_to_str (const grub_net_network_level_address_t *target, char *buf)
   switch (target->type)
     {
     case GRUB_NET_NETWORK_LEVEL_PROTOCOL_DHCP_RECV:
-      /* TRANSLATORS: it refers to the network address.  */
-      grub_strncpy (buf, "temporary", GRUB_NET_MAX_STR_ADDR_LEN);
+      COMPILE_TIME_ASSERT (sizeof ("temporary") < GRUB_NET_MAX_STR_ADDR_LEN);
+      grub_strcpy (buf, "temporary");
       return;
     case GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6:
       {
index 507811e68620480223d3daf7f3a274285b22ed5f..bed97600fa13bb4918c4a63c7caf1f56f8cded9e 100644 (file)
 
 void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n);
 char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src);
-char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, int c);
+
+static inline char *
+grub_strncpy (char *dest, const char *src, int c)
+{
+  char *p = dest;
+
+  while ((*p++ = *src++) != '\0' && --c)
+    ;
+
+  return dest;
+}
+
 static inline char *
 grub_stpcpy (char *dest, const char *src)
 {