Bug #72770 [Ana]: logical filter's trim is not trimming trailing spaces

From: Date: Sat, 06 Aug 2016 17:26:19 +0000
Subject: Bug #72770 [Ana]: logical filter's trim is not trimming trailing spaces
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-203004@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72770&edit=1

 ID:                 72770
 Updated by:         nikic@php.net
 Reported by:        yohgaki@php.net
 Summary:            logical filter's trim is not trimming trailing
                     spaces
 Status:             Analyzed
 Type:               Bug
 Package:            Filter related
 Operating System:   *
 PHP Version:        Irrelevant
 Assigned To:        yohgaki
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2016-08-06 04:57:21] 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.






------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72770&edit=1


Thread (4 messages)

« previous php.bugs (#203004) next »