php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72770 logical filter's trim is not trimming trailing spaces
Submitted: 2016-08-06 04:57 UTC Modified: 2016-08-07 01:47 UTC
From: yohgaki@php.net Assigned: yohgaki (profile)
Status: Not a bug Package: Filter related
PHP Version: Irrelevant OS: *
Private report: No CVE-ID: None
 [2016-08-06 04:57 UTC] yohgaki@php.net
Description:
------------
logical_filters.c uses following macro in filter_private.h for trimming strings.

#define PHP_FILTER_TRIM_DEFAULT_EX(p, len, return_if_empty) { \
	while ((len > 0)  && (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\v' || *p == '\n')) { \
		p++; \
		len--; \
	} \
	if (len < 1 && return_if_empty) { \
		RETURN_VALIDATION_FAILED("Filter validated value became empty after trim", 0); \
	} \
	if (len > 0) { \
		while (p[len-1] == ' ' || p[len-1] == '\t' || p[len-1] == '\r' || p[len-1] == '\v' || p[len-1] == '\n') { \
			len--; \
		} \
	} \
}

As you can see by the code, trailing spaces are not trimmed, but it only shorten length by counting spaces in it.

e.g. ' 1234  5678' would result in unwanted condition.





Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-06 04:57 UTC] yohgaki@php.net
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: yohgaki
 [2016-08-06 17:26 UTC] nikic@php.net
I don't understand. The code you show trims both the left and right side of the string. What's wrong with it? Please provide a reproduce case.
 [2016-08-07 01:47 UTC] yohgaki@php.net
-Status: Analyzed +Status: Not a bug
 [2016-08-07 01:47 UTC] yohgaki@php.net
Turned out strange behavior was not caused by this...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC