]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drivers/tty/hvc: Use strlcpy instead of strncpy
authorChen Gang <gang.chen@asianux.com>
Mon, 25 Feb 2013 17:43:25 +0000 (17:43 +0000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Tue, 5 Mar 2013 05:56:27 +0000 (16:56 +1100)
when strlen pi->location_code is larger than HVCS_CLC_LENGTH + 1,
    original implementation can not let hvcsd->p_location_code NUL terminated.
  so need fix it (also can simplify the code)

Signed-off-by: Chen Gang <gang.chen@asianux.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
drivers/tty/hvc/hvcs.c

index 1956593ee89d17b13d24e13c725eef8dd59cf7e7..81e939e90c4c44f7ead9bad36eac03f98f998421 100644 (file)
@@ -881,17 +881,12 @@ static struct vio_driver hvcs_vio_driver = {
 /* Only called from hvcs_get_pi please */
 static void hvcs_set_pi(struct hvcs_partner_info *pi, struct hvcs_struct *hvcsd)
 {
-       int clclength;
-
        hvcsd->p_unit_address = pi->unit_address;
        hvcsd->p_partition_ID  = pi->partition_ID;
-       clclength = strlen(&pi->location_code[0]);
-       if (clclength > HVCS_CLC_LENGTH)
-               clclength = HVCS_CLC_LENGTH;
 
        /* copy the null-term char too */
-       strncpy(&hvcsd->p_location_code[0],
-                       &pi->location_code[0], clclength + 1);
+       strlcpy(&hvcsd->p_location_code[0],
+                       &pi->location_code[0], sizeof(hvcsd->p_location_code));
 }
 
 /*