From a849ec29c1f1adb6bef51d050f0c782d86b826ca Mon Sep 17 00:00:00 2001 From: hartkopp Date: Wed, 13 Dec 2006 07:47:34 +0000 Subject: [PATCH] Preventing procfs output to overflow PAGE_SIZE. Cosmetics in 2.4 af_can.c (looked broken & is unusual in the Kernel even when it's ok for the compiler). git-svn-id: svn://svn.berlios.de//socketcan/trunk@121 030b6a49-0b11-0410-94ab-b0dab22257f2 --- kernel/2.4/can/af_can.c | 3 +-- kernel/2.4/can/bcm.c | 4 ++-- kernel/2.4/can/proc.c | 18 ++++++++++++++++++ kernel/2.6/net/can/bcm.c | 4 ++-- kernel/2.6/net/can/proc.c | 18 ++++++++++++++++++ 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/kernel/2.4/can/af_can.c b/kernel/2.4/can/af_can.c index f8f434a..879ed17 100644 --- a/kernel/2.4/can/af_can.c +++ b/kernel/2.4/can/af_can.c @@ -114,8 +114,7 @@ struct notifier { static LIST_HEAD(notifier_list); static rwlock_t notifier_lock = RW_LOCK_UNLOCKED; -static -struct dev_rcv_lists rx_alldev_list; +static struct dev_rcv_lists rx_alldev_list; struct dev_rcv_lists *rx_dev_list; rwlock_t rcv_lists_lock = RW_LOCK_UNLOCKED; diff --git a/kernel/2.4/can/bcm.c b/kernel/2.4/can/bcm.c index 0736a02..7399bf2 100644 --- a/kernel/2.4/can/bcm.c +++ b/kernel/2.4/can/bcm.c @@ -383,7 +383,7 @@ static int bcm_read_proc(char *page, char **start, off_t off, len += snprintf(page + len, PAGE_SIZE - len, "%s%ld%%\n", (reduction == 100)?"near ":"", reduction); - if (len >= PAGE_SIZE - 100) { + if (len > PAGE_SIZE - 200) { /* mark output cut off */ len += snprintf(page + len, PAGE_SIZE - len, "(..)\n"); break; @@ -402,7 +402,7 @@ static int bcm_read_proc(char *page, char **start, off_t off, len += snprintf(page + len, PAGE_SIZE - len, "# sent %ld\n", op->frames_abs); - if (len >= PAGE_SIZE - 100) { + if (len > PAGE_SIZE - 100) { /* mark output cut off */ len += snprintf(page + len, PAGE_SIZE - len, "(..)\n"); break; diff --git a/kernel/2.4/can/proc.c b/kernel/2.4/can/proc.c index e9c0cee..23dc07c 100644 --- a/kernel/2.4/can/proc.c +++ b/kernel/2.4/can/proc.c @@ -367,6 +367,9 @@ static int can_proc_read_rcvlist_all(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } len += snprintf(page + len, PAGE_SIZE - len, "\n"); @@ -398,6 +401,9 @@ static int can_proc_read_rcvlist_fil(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } len += snprintf(page + len, PAGE_SIZE - len, "\n"); @@ -429,6 +435,9 @@ static int can_proc_read_rcvlist_inv(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } len += snprintf(page + len, PAGE_SIZE - len, "\n"); @@ -470,6 +479,9 @@ static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } len += snprintf(page + len, PAGE_SIZE - len, "\n"); @@ -501,6 +513,9 @@ static int can_proc_read_rcvlist_eff(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } len += snprintf(page + len, PAGE_SIZE - len, "\n"); @@ -532,6 +547,9 @@ static int can_proc_read_rcvlist_err(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } len += snprintf(page + len, PAGE_SIZE - len, "\n"); diff --git a/kernel/2.6/net/can/bcm.c b/kernel/2.6/net/can/bcm.c index 7ab8709..e4d5727 100644 --- a/kernel/2.6/net/can/bcm.c +++ b/kernel/2.6/net/can/bcm.c @@ -416,7 +416,7 @@ static int bcm_read_proc(char *page, char **start, off_t off, len += snprintf(page + len, PAGE_SIZE - len, "%s%ld%%\n", (reduction == 100)?"near ":"", reduction); - if (len >= PAGE_SIZE - 100) { + if (len > PAGE_SIZE - 200) { /* mark output cut off */ len += snprintf(page + len, PAGE_SIZE - len, "(..)\n"); break; @@ -435,7 +435,7 @@ static int bcm_read_proc(char *page, char **start, off_t off, len += snprintf(page + len, PAGE_SIZE - len, "# sent %ld\n", op->frames_abs); - if (len >= PAGE_SIZE - 100) { + if (len > PAGE_SIZE - 100) { /* mark output cut off */ len += snprintf(page + len, PAGE_SIZE - len, "(..)\n"); break; diff --git a/kernel/2.6/net/can/proc.c b/kernel/2.6/net/can/proc.c index 7182bae..6f08010 100644 --- a/kernel/2.6/net/can/proc.c +++ b/kernel/2.6/net/can/proc.c @@ -362,6 +362,9 @@ static int can_proc_read_rcvlist_all(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } rcu_read_unlock(); @@ -392,6 +395,9 @@ static int can_proc_read_rcvlist_fil(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } rcu_read_unlock(); @@ -422,6 +428,9 @@ static int can_proc_read_rcvlist_inv(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } rcu_read_unlock(); @@ -462,6 +471,9 @@ static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } rcu_read_unlock(); @@ -492,6 +504,9 @@ static int can_proc_read_rcvlist_eff(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } rcu_read_unlock(); @@ -522,6 +537,9 @@ static int can_proc_read_rcvlist_err(char *page, char **start, off_t off, } else len += snprintf(page + len, PAGE_SIZE - len, " (%s: no entry)\n", DNAME(d->dev)); + + if (len > PAGE_SIZE - 100) + break; /* exit on end of buffer */ } rcu_read_unlock(); -- 2.39.2