public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] mtrace: make shell commands robust against meta characters
@ 2024-06-20 12:41 Andreas Schwab
  2024-06-20 18:03 ` Carlos O'Donell
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Schwab @ 2024-06-20 12:41 UTC (permalink / raw)
  To: libc-alpha

Use the list form of the open function to avoid interpreting meta
characters in the arguments.
---
 malloc/mtrace.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl
index ba14be6cae..1d5c723637 100644
--- a/malloc/mtrace.pl
+++ b/malloc/mtrace.pl
@@ -86,7 +86,7 @@ if ($#ARGV == 0) {
     }
     # Set the environment variable LD_TRACE_LOADED_OBJECTS to 2 so the
     # executable is also printed.
-    if (open (locs, "env LD_TRACE_LOADED_OBJECTS=2 $prog |")) {
+    if (open (locs, "-|", "env", "LD_TRACE_LOADED_OBJECTS=2", $prog)) {
 	while (<locs>) {
 	    chop;
 	    if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) {
@@ -103,7 +103,7 @@ if ($#ARGV == 0) {
 sub addr2line {
     my $addr = pop(@_);
     my $prog = pop(@_);
-    if (open (ADDR, "addr2line -e $prog $addr|")) {
+    if (open (ADDR, "-|", "addr2line", "-e", $prog, $addr)) {
 	my $line = <ADDR>;
 	chomp $line;
 	close (ADDR);
-- 
2.45.2


-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

* Re: [PATCH] mtrace: make shell commands robust against meta characters
  2024-06-20 12:41 [PATCH] mtrace: make shell commands robust against meta characters Andreas Schwab
@ 2024-06-20 18:03 ` Carlos O'Donell
  0 siblings, 0 replies; 2+ messages in thread
From: Carlos O'Donell @ 2024-06-20 18:03 UTC (permalink / raw)
  To: Andreas Schwab, libc-alpha

On 6/20/24 8:41 AM, Andreas Schwab wrote:
> Use the list form of the open function to avoid interpreting meta
> characters in the arguments.

Agreed. LGTM.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> ---
>  malloc/mtrace.pl | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl
> index ba14be6cae..1d5c723637 100644
> --- a/malloc/mtrace.pl
> +++ b/malloc/mtrace.pl
> @@ -86,7 +86,7 @@ if ($#ARGV == 0) {
>      }
>      # Set the environment variable LD_TRACE_LOADED_OBJECTS to 2 so the
>      # executable is also printed.
> -    if (open (locs, "env LD_TRACE_LOADED_OBJECTS=2 $prog |")) {
> +    if (open (locs, "-|", "env", "LD_TRACE_LOADED_OBJECTS=2", $prog)) {

OK, locs specified and "-|" specifies command which pipes output to caller.

>  	while (<locs>) {
>  	    chop;
>  	    if (/^.*=> (.*) .(0x[0123456789abcdef]*).$/) {
> @@ -103,7 +103,7 @@ if ($#ARGV == 0) {
>  sub addr2line {
>      my $addr = pop(@_);
>      my $prog = pop(@_);
> -    if (open (ADDR, "addr2line -e $prog $addr|")) {
> +    if (open (ADDR, "-|", "addr2line", "-e", $prog, $addr)) {

OK. Likewise.

>  	my $line = <ADDR>;
>  	chomp $line;
>  	close (ADDR);

-- 
Cheers,
Carlos.


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

end of thread, other threads:[~2024-06-20 18:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-20 12:41 [PATCH] mtrace: make shell commands robust against meta characters Andreas Schwab
2024-06-20 18:03 ` Carlos O'Donell

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 read-only IMAP folder(s) and NNTP newsgroup(s).