linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes
@ 2005-02-05 17:18 Michael Buesch
  2005-02-05 18:15 ` [PATCH, UDEV] change no_trailing_slash() to remove all Kay Sievers
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Michael Buesch @ 2005-02-05 17:18 UTC (permalink / raw)
  To: linux-hotplug


[-- Attachment #1.1: Type: text/plain, Size: 262 bytes --]

Hi,

This changes no_trailing_slash() to remove all trailing slashes
and not just the last one.
This protects against crazy users which do:
export SYSFS_PATH="/sys//"
or something similiar.

-- 
Regards Michael Buesch  [ http://www.tuxsoft.de.vu ]



[-- Attachment #1.2: udev_no_trailing_slash.diff --]
[-- Type: text/x-diff, Size: 414 bytes --]

===== udev_utils.c 1.25 vs edited =====
--- 1.25/udev_utils.c	2004-12-20 22:10:57 +01:00
+++ edited/udev_utils.c	2005-02-05 18:13:46 +01:00
@@ -200,11 +200,11 @@
 
 void no_trailing_slash(char *path)
 {
-	int len;
+	size_t len;
 
 	len = strlen(path);
-	if (len > 0 && path[len-1] == '/')
-		path[len-1] = '\0';
+	while (len > 0 && path[len-1] == '/')
+		path[--len] = '\0';
 }
 
 struct files {

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [PATCH, UDEV] change no_trailing_slash() to remove all
  2005-02-05 17:18 [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch
@ 2005-02-05 18:15 ` Kay Sievers
  2005-02-05 22:04 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing Paul Jackson
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Kay Sievers @ 2005-02-05 18:15 UTC (permalink / raw)
  To: linux-hotplug

On Sat, 2005-02-05 at 18:18 +0100, Michael Buesch wrote:
> This changes no_trailing_slash() to remove all trailing slashes
> and not just the last one.
> This protects against crazy users which do:
> export SYSFS_PATH="/sys//"
> or something similiar.

Applied.

Thanks,
Kay



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: [PATCH, UDEV] change no_trailing_slash() to remove all trailing
  2005-02-05 17:18 [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch
  2005-02-05 18:15 ` [PATCH, UDEV] change no_trailing_slash() to remove all Kay Sievers
@ 2005-02-05 22:04 ` Paul Jackson
  2005-02-05 22:36 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Paul Jackson @ 2005-02-05 22:04 UTC (permalink / raw)
  To: linux-hotplug

Michael wrote:
> 	while (len > 0 && path[len-1] = '/')

I think you'd better make that:

	while (len > 1 && path[len-1] = '/')

or else you can eat your last slash.

The call no_trailing_slash("/") should produce "/", not "".

Not that anyone is likely to call no_trailing_slash("////")
very often ;).

-- 
                  I won't rest till it's the best ...
                  Programmer, Linux Scalability
                  Paul Jackson <pj@sgi.com> 1.650.933.1373, 1.925.600.0401


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes
  2005-02-05 17:18 [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch
  2005-02-05 18:15 ` [PATCH, UDEV] change no_trailing_slash() to remove all Kay Sievers
  2005-02-05 22:04 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing Paul Jackson
@ 2005-02-05 22:36 ` Michael Buesch
  2005-02-06  1:11 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing Paul Jackson
  2005-02-06  9:54 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Buesch @ 2005-02-05 22:36 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 696 bytes --]

Quoting Paul Jackson <pj@sgi.com>:
> Michael wrote:
> > 	while (len > 0 && path[len-1] == '/')
> 
> I think you'd better make that:
> 
> 	while (len > 1 && path[len-1] == '/')
> 
> or else you can eat your last slash.
> 
> The call no_trailing_slash("/") should produce "/", not "".

Well, I would call that expected behaviour.
Consider the following:
char buf[SIZE];
strcpy(buf, "///");
no_trailing_slash(buf);
strcat(buf, "/foo/bar");

I would expect that to expand to "/foo/bar" and _not_
to "//foo/bar" as you suggest.

> Not that anyone is likely to call no_trailing_slash("////")
> very often ;).
> 

-- 
Regards Michael Buesch  [ http://www.tuxsoft.de.vu ]



[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [PATCH, UDEV] change no_trailing_slash() to remove all trailing
  2005-02-05 17:18 [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch
                   ` (2 preceding siblings ...)
  2005-02-05 22:36 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch
@ 2005-02-06  1:11 ` Paul Jackson
  2005-02-06  9:54 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch
  4 siblings, 0 replies; 6+ messages in thread
From: Paul Jackson @ 2005-02-06  1:11 UTC (permalink / raw)
  To: linux-hotplug

What if someone does:

    strcpy(buf, "/");
    no_trailing_slash(buf);
    strcat(buf, "foo");

Would you expect "foo", or "/foo" ?

Actually, I did not expect this to be called in the middle
of a construction, after only explicit constant strings
had been added.

I would have expected it to be called after the final
construction, following the concatenation of a variable
string.

And I would have expected it to scrupulously avoid changing
the meaning of the path - just cosmetic trimming.

But apparently my expectations are confused.  Feel free to
dismiss my comments.

-- 
                  I won't rest till it's the best ...
                  Programmer, Linux Scalability
                  Paul Jackson <pj@sgi.com> 1.650.933.1373, 1.925.600.0401


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

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

* Re: [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes
  2005-02-05 17:18 [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch
                   ` (3 preceding siblings ...)
  2005-02-06  1:11 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing Paul Jackson
@ 2005-02-06  9:54 ` Michael Buesch
  4 siblings, 0 replies; 6+ messages in thread
From: Michael Buesch @ 2005-02-06  9:54 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 1437 bytes --]

Quoting Paul Jackson <pj@sgi.com>:
> What if someone does:
> 
>     strcpy(buf, "/");
>     no_trailing_slash(buf);
>     strcat(buf, "foo");
> 
> Would you expect "foo", or "/foo" ?

I would expect "foo".
It's the function semantics:
no_trailing_slash means (at least for me) clearly,
that there will be "no trailing slash" under any circumstances in
the string.
It should be the caller's job to ensure, that we have a
valid path after cutting of all trailing slashes.

	strcpy(buf, "/");
	no_trailing_slash(buf);
	if (buf[0] == '\0')
		strcat(buf, "/");
	strcat(buf, "foo");

But having saied this all, I can't find where this
actually happens in the udev code. I did a very quick
search even before I submitted the code, but I could only
find places like this, which will always result
in a valid path:

	no_trailing_slash(buf);
	strcat(buf, "/foo");

> Actually, I did not expect this to be called in the middle
> of a construction, after only explicit constant strings
> had been added.
> 
> I would have expected it to be called after the final
> construction, following the concatenation of a variable
> string.
> 
> And I would have expected it to scrupulously avoid changing
> the meaning of the path - just cosmetic trimming.
> 
> But apparently my expectations are confused.  Feel free to
> dismiss my comments.
> 

-- 
Regards Michael Buesch  [ http://www.tuxsoft.de.vu ]



[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2005-02-06  9:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-05 17:18 [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch
2005-02-05 18:15 ` [PATCH, UDEV] change no_trailing_slash() to remove all Kay Sievers
2005-02-05 22:04 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing Paul Jackson
2005-02-05 22:36 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch
2005-02-06  1:11 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing Paul Jackson
2005-02-06  9:54 ` [PATCH, UDEV] change no_trailing_slash() to remove all trailing slashes Michael Buesch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).