misc/140690: swab() with negative len should do nothing

Jeremy Huddleston jeremyhu at apple.com
Thu Nov 19 02:50:02 UTC 2009


>Number:         140690
>Category:       misc
>Synopsis:       swab() with negative len should do nothing
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 19 02:50:01 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator:     Jeremy Huddleston
>Release:        MAIN
>Organization:
Apple
>Environment:
NA
>Description:
src/lib/libc/string/swab.c has a bug when len < 0.  The "round to multiple of 8" for loop will still STEP with negative values.  This should not be the case.  Simple patch is attached.
>How-To-Repeat:

>Fix:
--- swab.c.bsdnew	2009-11-18 18:24:38.000000000 -0800
+++ swab.c	2009-11-18 18:40:17.000000000 -0800
@@ -45,6 +45,8 @@ swab(const void * __restrict from, void 
 	int n;
 	char *fp, *tp;
 
+	if (len <= 0)
+		return;
 	n = len >> 1;
 	fp = (char *)from;
 	tp = (char *)to;


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list