All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/strutils: make left and right trims more robust
@ 2016-09-04 10:15 Sami Kerola
  2016-09-29  9:56 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Sami Kerola @ 2016-09-04 10:15 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Do not follow null pointer, and stop going any further when
ltrim_whitespace() is at the end of a string.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 include/strutils.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/strutils.h b/include/strutils.h
index 52c28b7..51d9c9f 100644
--- a/include/strutils.h
+++ b/include/strutils.h
@@ -178,8 +178,11 @@ static inline const char *skip_blank(const char *p)
  */
 static inline size_t rtrim_whitespace(unsigned char *str)
 {
-	size_t i = strlen((char *) str);
+	size_t i;
 
+	if (!str)
+		return 0;
+	i = strlen((char *) str);
 	while (i) {
 		i--;
 		if (!isspace(str[i])) {
@@ -200,7 +203,9 @@ static inline size_t ltrim_whitespace(unsigned char *str)
 	size_t len;
 	unsigned char *p;
 
-	for (p = str; p && isspace(*p); p++);
+	if (!str)
+		return 0;
+	for (p = str; *p && isspace(*p); p++);
 
 	len = strlen((char *) p);
 
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] lib/strutils: make left and right trims more robust
  2016-09-04 10:15 [PATCH] lib/strutils: make left and right trims more robust Sami Kerola
@ 2016-09-29  9:56 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2016-09-29  9:56 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Sep 04, 2016 at 11:15:34AM +0100, Sami Kerola wrote:
>  include/strutils.h | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-29  9:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-04 10:15 [PATCH] lib/strutils: make left and right trims more robust Sami Kerola
2016-09-29  9:56 ` Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.