NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/49632: t_strtol improper check of endptr



>Number:         49632
>Category:       lib
>Synopsis:       t_strtol improper check of endptr
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Feb 03 00:00:00 +0000 2015
>Originator:     Kamil Rytarowski
>Release:        current
>Organization:
>Environment:
NetBSD chieftec 7.99.1 NetBSD 7.99.1 (GENERIC) #0: Fri Nov  7 22:04:53 CET 2014  kamil@chieftec:/tmp/netbsd-tmp/sys/arch/amd64/compile/GENERIC amd64

>Description:
t_strtol tests improperly check for valid endptr.
If provided endptr from test matrix is NULL then it skips checking for proper endptr.

After fixing it, fix 3 tests.

See patch for details.
>How-To-Repeat:
N/A
>Fix:
commit a21d6cf264a73d6549b9c6f011f99bc9f9a93b72
Author: Kamil Rytarowski <n54%gmx.com@localhost>
Date:   Mon Feb 2 23:09:28 2015 +0000

    t_strtol fix

diff --git a/lib/libc/stdlib/t_strtol.c b/lib/libc/stdlib/t_strtol.c
index 5a0c6d0..e6165b2 100644
--- a/lib/libc/stdlib/t_strtol.c
+++ b/lib/libc/stdlib/t_strtol.c
@@ -59,7 +59,8 @@ check(struct test *t, long int li, long long int lli, char *end)
 		atf_tc_fail_nonfatal("strtoll(%s, NULL, %d) failed "
 		    "(rv = %lld)", t->str, t->base, lli);
 
-	if (t->end != NULL && strcmp(t->end, end) != 0)
+	if ((t->end != NULL && strcmp(t->end, end) != 0) ||
+	    (t->end == NULL && *end != '\0'))
 		atf_tc_fail_nonfatal("invalid end pointer ('%s') from "
 		    "strtol(%s, &end, %d)", end, t->str, t->base);
 }
@@ -89,8 +90,8 @@ ATF_TC_BODY(strtol_base, tc)
 		{ "12579781",			 123456789, 14, NULL	},
 		{ "AC89BC9",			 123456789, 15, NULL	},
 		{ "75BCD15",			 123456789, 16, NULL	},
-		{ "123456789",			    342391,  8, NULL	},
-		{ "0123456789",			    342391,  0, NULL	},
+		{ "1234567",			    342391,  8, NULL	},
+		{ "01234567",			    342391,  0, NULL	},
 		{ "0123456789",			 123456789, 10, NULL	},
 		{ "0x75bcd15",		         123456789,  0, NULL	},
 	};
@@ -121,7 +122,7 @@ ATF_TC_BODY(strtol_case, tc)
 		{ "abcd",	0xabcd, 16, NULL	},
 		{ "     dcba",	0xdcba, 16, NULL	},
 		{ "abcd dcba",	0xabcd, 16, " dcba"	},
-		{ "abc0x123",	0xabc0, 16, NULL	},
+		{ "abc0x123",	0xabc0, 16, "x123"	},
 		{ "abcd\0x123",	0xabcd, 16, "\0x123"	},
 		{ "ABCD",	0xabcd, 16, NULL	},
 		{ "aBcD",	0xabcd, 16, NULL	},



Home | Main Index | Thread Index | Old Index