OSDN Git Service

[PATCH] isdn: avoid copying overly-long strings
authorWilly Tarreau <w@1wt.eu>
Mon, 10 Dec 2007 06:17:13 +0000 (07:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 10 Dec 2007 06:18:34 +0000 (07:18 +0100)
Backport of 2.6 commit 0f13864e5b24d9cbe18d125d41bfa4b726a82e40 by Karsten Keil

Addresses http://bugzilla.kernel.org/show_bug.cgi?id=9416

Signed-off-by: Willy Tarreau <w@1wt.eu>
drivers/isdn/isdn_net.c

index 0a5bea3..e85fcc4 100644 (file)
@@ -2159,7 +2159,7 @@ isdn_net_find_icall(int di, int ch, int idx, setup_parm *setup)
        isdn_net_dev *p;
        isdn_net_phone *n;
        ulong flags;
-       char nr[32];
+       char nr[ISDN_MSNLEN];
        char *my_eaz;
 
        /* Search name in netdev-chain */
@@ -2169,8 +2169,10 @@ isdn_net_find_icall(int di, int ch, int idx, setup_parm *setup)
                nr[0] = '0';
                nr[1] = '\0';
                printk(KERN_INFO "isdn_net: Incoming call without OAD, assuming '0'\n");
-       } else
-               strcpy(nr, setup->phone);
+       } else {
+               strncpy(nr, setup->phone, ISDN_MSNLEN - 1);
+               nr[ISDN_MSNLEN - 1] = 0;
+       }
        si1 = (int) setup->si1;
        si2 = (int) setup->si2;
        if (!setup->eazmsn[0]) {
@@ -2855,7 +2857,8 @@ isdn_net_setcfg(isdn_net_ioctl_cfg * cfg)
                                chidx = -1;
                        }
                }
-               strcpy(lp->msn, cfg->eaz);
+               strncpy(lp->msn, cfg->eaz, sizeof(lp->msn) - 1);
+               lp->msn[sizeof(lp->msn) - 1] = 0;
                lp->pre_device = drvidx;
                lp->pre_channel = chidx;
                lp->onhtime = cfg->onhtime;
@@ -3004,7 +3007,8 @@ isdn_net_addphone(isdn_net_ioctl_phone * phone)
        if (p) {
                if (!(n = (isdn_net_phone *) kmalloc(sizeof(isdn_net_phone), GFP_KERNEL)))
                        return -ENOMEM;
-               strcpy(n->num, phone->phone);
+               strncpy(n->num, phone->phone, sizeof(n->num) - 1);
+               n->num[sizeof(n->num) - 1] = 0;
                n->next = p->local->phone[phone->outgoing & 1];
                p->local->phone[phone->outgoing & 1] = n;
                return 0;