From: zab Date: Fri, 17 Oct 2003 22:43:52 +0000 (+0000) Subject: - don't accidentally copy a whole page of debug log to the user when there X-Git-Tag: v1_7_0_51~2^7~379 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=2c62dce1d5cde3bb823c37dbcf798ea5ff3084e9;p=fs%2Flustre-release.git - don't accidentally copy a whole page of debug log to the user when there is less than a page of data in the log --- diff --git a/lnet/libcfs/debug.c b/lnet/libcfs/debug.c index 9671278..a42d422 100644 --- a/lnet/libcfs/debug.c +++ b/lnet/libcfs/debug.c @@ -648,7 +648,7 @@ int portals_debug_mark_buffer(char *text) __s32 portals_debug_copy_to_user(char *buf, unsigned long len) { int rc; - unsigned long debug_off, i, off, copied; + unsigned long total, debug_off, i, off, copied; unsigned long flags; struct page *page; LIST_HEAD(my_pages); @@ -676,16 +676,19 @@ __s32 portals_debug_copy_to_user(char *buf, unsigned long len) goto cleanup; } - if (debug_wrapped) + if (debug_wrapped) { off = debug_off + 1; - else + total = debug_size; + } else { off = 0; + total = debug_off; + } copied = 0; list_for_each(pos, &my_pages) { unsigned long to_copy; page = list_entry(pos, struct page, list); - to_copy = min(debug_size - off, PAGE_SIZE); + to_copy = min(total - off, PAGE_SIZE); if (to_copy == 0) { off = 0; to_copy = min(debug_size - off, PAGE_SIZE); @@ -694,7 +697,7 @@ finish_partial: memcpy(kmap(page), debug_buf + off, to_copy); kunmap(page); copied += to_copy; - if (copied >= (debug_wrapped ? debug_size : debug_off)) + if (copied >= total) break; off += to_copy; diff --git a/lustre/portals/libcfs/debug.c b/lustre/portals/libcfs/debug.c index 9671278..a42d422 100644 --- a/lustre/portals/libcfs/debug.c +++ b/lustre/portals/libcfs/debug.c @@ -648,7 +648,7 @@ int portals_debug_mark_buffer(char *text) __s32 portals_debug_copy_to_user(char *buf, unsigned long len) { int rc; - unsigned long debug_off, i, off, copied; + unsigned long total, debug_off, i, off, copied; unsigned long flags; struct page *page; LIST_HEAD(my_pages); @@ -676,16 +676,19 @@ __s32 portals_debug_copy_to_user(char *buf, unsigned long len) goto cleanup; } - if (debug_wrapped) + if (debug_wrapped) { off = debug_off + 1; - else + total = debug_size; + } else { off = 0; + total = debug_off; + } copied = 0; list_for_each(pos, &my_pages) { unsigned long to_copy; page = list_entry(pos, struct page, list); - to_copy = min(debug_size - off, PAGE_SIZE); + to_copy = min(total - off, PAGE_SIZE); if (to_copy == 0) { off = 0; to_copy = min(debug_size - off, PAGE_SIZE); @@ -694,7 +697,7 @@ finish_partial: memcpy(kmap(page), debug_buf + off, to_copy); kunmap(page); copied += to_copy; - if (copied >= (debug_wrapped ? debug_size : debug_off)) + if (copied >= total) break; off += to_copy;