Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #24027

Re: Wrapping existing UNIX commands in C

From Nobody <nobody@nowhere.com>
Subject Re: Wrapping existing UNIX commands in C
Date 2012-07-31 14:53 +0100
Message-Id <pan.2012.07.31.13.53.43.808000@nowhere.com>
Newsgroups comp.lang.c
References <jv3jqk$r1t$1@speranza.aioe.org> <jv3q1s$c09$1@dont-email.me> <pan.2012.07.30.11.13.25.146000@nowhere.com> <jv5r18$o93$1@speranza.aioe.org>
Organization Zen Internet

Show all headers | View raw


On Mon, 30 Jul 2012 13:26:34 +0200, jacob navia wrote:

>> I have seen real-world code which did:
>>
>> 	char buf[100];
>> 	sprintf(buf, "rm %s", filename);
>> 	system(buf);
> 
> Yes, the hard coded buffer size is a problem but in principle
> this thing will work as intended.

The lack of quoting/escaping is a bigger problem than the fixed buffer
size. Apart from the need to protect against interpretation by the shell,
"rm" will interpret the argument as an option if it begins with a dash.

Using a relative path to "rm" means that it may run something other than
/bin/rm.

And performance is several orders of magnitude worse than remove() or
unlink() (fork() and/or exec() can be particularly expensive).

At least system() usually does the right thing with respect to signals;
the situation for popen() is much more complex.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Wrapping existing UNIX commands in C Chicken McNuggets <chicken@mcnuggets.com> - 2012-07-29 16:11 +0100
  Re: Wrapping existing UNIX commands in C Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-29 11:18 -0400
    Re: Wrapping existing UNIX commands in C Chicken McNuggets <chicken@mcnuggets.com> - 2012-07-29 16:24 +0100
    Re: Wrapping existing UNIX commands in C "China Blue [Tor], Meersburg" <chine.bleu@yahoo.com> - 2012-07-29 08:34 -0700
      Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-07-29 12:05 -0700
        Re: Wrapping existing UNIX commands in C "China Blue [Tor], Meersburg" <chine.bleu@yahoo.com> - 2012-07-29 14:00 -0700
          Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-07-29 15:19 -0700
          Re: Wrapping existing UNIX commands in C Rui Maciel <rui.maciel@gmail.com> - 2012-07-30 00:35 +0100
            Re: Wrapping existing UNIX commands in C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-07-30 14:54 +0000
              Re: Wrapping existing UNIX commands in C Chicken McNuggets <chicken@mcnuggets.com> - 2012-07-30 17:15 +0100
              Re: Wrapping existing UNIX commands in C James Kuyper <jameskuyper@verizon.net> - 2012-07-30 12:44 -0400
                Re: Wrapping existing UNIX commands in C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-08-02 13:51 +0000
          Re: Wrapping existing UNIX commands in C jacob navia <jacob@spamsink.net> - 2012-07-30 11:13 +0200
          Re: Wrapping existing UNIX commands in C Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-07-30 01:59 -0700
    Re: Wrapping existing UNIX commands in C gazelle@shell.xmission.com (Kenny McCormack) - 2012-07-29 17:10 +0000
      Re: Wrapping existing UNIX commands in C tom st denis <tom@iahu.ca> - 2012-07-31 14:55 -0700
        Re: Wrapping existing UNIX commands in C jacob navia <jacob@spamsink.net> - 2012-08-01 00:24 +0200
          Re: Wrapping existing UNIX commands in C tom st denis <tom@iahu.ca> - 2012-08-02 06:12 -0700
  Re: Wrapping existing UNIX commands in C "Heinrich Wolf" <invalid@invalid.invalid> - 2012-07-29 17:20 +0200
    Re: Wrapping existing UNIX commands in C Chicken McNuggets <chicken@mcnuggets.com> - 2012-07-29 16:24 +0100
    Re: Wrapping existing UNIX commands in C Ike Naar <ike@sverige.freeshell.org> - 2012-07-29 21:41 +0000
      Re: Wrapping existing UNIX commands in C "Heinrich Wolf" <invalid@invalid.invalid> - 2012-07-30 06:46 +0200
    Re: Wrapping existing UNIX commands in C "Heinrich Wolf" <invalid@invalid.invalid> - 2012-07-30 06:49 +0200
  Re: Wrapping existing UNIX commands in C "China Blue [Tor], Meersburg" <chine.bleu@yahoo.com> - 2012-07-29 08:31 -0700
    Re: Wrapping existing UNIX commands in C Ike Naar <ike@sverige.freeshell.org> - 2012-07-29 21:46 +0000
  Re: Wrapping existing UNIX commands in C Stephen Sprunk <stephen@sprunk.org> - 2012-07-29 11:57 -0500
    Re: Wrapping existing UNIX commands in C Nobody <nobody@nowhere.com> - 2012-07-30 12:13 +0100
      Re: Wrapping existing UNIX commands in C jacob navia <jacob@spamsink.net> - 2012-07-30 13:26 +0200
        Re: Wrapping existing UNIX commands in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-07-30 12:39 +0100
          Re: Wrapping existing UNIX commands in C Mark Bluemel <mark_bluemel@pobox.com> - 2012-07-30 13:16 +0100
            Re: Wrapping existing UNIX commands in C BGB <cr88192@hotmail.com> - 2012-07-30 12:39 -0500
          Re: Wrapping existing UNIX commands in C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-07-30 15:02 +0000
        Re: Wrapping existing UNIX commands in C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-07-30 15:18 +0000
        Re: Wrapping existing UNIX commands in C Nobody <nobody@nowhere.com> - 2012-07-31 14:53 +0100
        Re: Wrapping existing UNIX commands in C tom st denis <tom@iahu.ca> - 2012-08-02 06:21 -0700
    Re: Wrapping existing UNIX commands in C Chicken McNuggets <chicken@mcnuggets.com> - 2012-07-30 18:10 +0100
      Re: Wrapping existing UNIX commands in C Paul <nospam@needed.com> - 2012-07-30 13:30 -0400
      Re: Wrapping existing UNIX commands in C James Kuyper <jameskuyper@verizon.net> - 2012-07-30 13:34 -0400
        Re: Wrapping existing UNIX commands in C gazelle@shell.xmission.com (Kenny McCormack) - 2012-08-15 21:21 +0000
          Re: Wrapping existing UNIX commands in C Stephen Sprunk <stephen@sprunk.org> - 2012-08-15 17:17 -0500
      Re: Wrapping existing UNIX commands in C Stephen Sprunk <stephen@sprunk.org> - 2012-07-30 13:18 -0500
      Re: Wrapping existing UNIX commands in C Cal Dershowitz <cal@example.invalid> - 2012-08-01 21:08 -0600
        Re: Wrapping existing UNIX commands in C gazelle@shell.xmission.com (Kenny McCormack) - 2012-08-02 12:20 +0000
          Re: Wrapping existing UNIX commands in C tom st denis <tom@iahu.ca> - 2012-08-02 06:15 -0700
            Re: Wrapping existing UNIX commands in C gazelle@shell.xmission.com (Kenny McCormack) - 2012-08-02 14:16 +0000
              Re: Wrapping existing UNIX commands in C Kenneth Brody <kenbrody@spamcop.net> - 2012-08-02 11:33 -0400
              Re: Wrapping existing UNIX commands in C tom st denis <tom@iahu.ca> - 2012-08-02 11:51 -0700
                Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-08-02 15:03 -0700
                Re: Wrapping existing UNIX commands in C tom st denis <tom@iahu.ca> - 2012-08-02 18:46 -0700
                Re: Wrapping existing UNIX commands in C gazelle@shell.xmission.com (Kenny McCormack) - 2012-08-03 02:18 +0000
                Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-08-02 21:07 -0700
                Re: Wrapping existing UNIX commands in C Chicken McNuggets <chicken@mcnuggets.com> - 2012-08-04 10:40 +0100
                Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-08-04 03:22 -0700
                Re: Wrapping existing UNIX commands in C "Heinrich Wolf" <invalid@invalid.invalid> - 2012-08-04 12:34 +0200
                Re: Wrapping existing UNIX commands in C gazelle@shell.xmission.com (Kenny McCormack) - 2012-08-04 13:25 +0000
                Re: Wrapping existing UNIX commands in C Kenneth Brody <kenbrody@spamcop.net> - 2012-08-15 13:52 -0400
                Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-08-04 16:26 -0700
                Re: Wrapping existing UNIX commands in C Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-05 03:27 -0700
                Re: Wrapping existing UNIX commands in C gwowen <gwowen@gmail.com> - 2012-08-06 01:50 -0700
                Re: Wrapping existing UNIX commands in C James Kuyper <jameskuyper@verizon.net> - 2012-08-06 07:15 -0400
                Re: Wrapping existing UNIX commands in C gwowen <gwowen@gmail.com> - 2012-08-06 04:25 -0700
                Re: Wrapping existing UNIX commands in C James Kuyper <jameskuyper@verizon.net> - 2012-08-06 09:14 -0400
                Re: Wrapping existing UNIX commands in C gazelle@shell.xmission.com (Kenny McCormack) - 2012-08-06 14:14 +0000
                Re: Wrapping existing UNIX commands in C gwowen <gwowen@gmail.com> - 2012-08-06 07:43 -0700
                Re: Wrapping existing UNIX commands in C James Kuyper <jameskuyper@verizon.net> - 2012-08-06 11:52 -0400
                Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-08-06 11:37 -0700
                Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-08-06 11:34 -0700
                Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-08-06 11:53 -0700
                Re: Wrapping existing UNIX commands in C gwowen <gwowen@gmail.com> - 2012-08-07 00:33 -0700
                Re: Wrapping existing UNIX commands in C James Kuyper <jameskuyper@verizon.net> - 2012-08-07 06:44 -0400
                Re: Wrapping existing UNIX commands in C gwowen <gwowen@gmail.com> - 2012-08-07 05:15 -0700
                Re: Wrapping existing UNIX commands in C James Kuyper <jameskuyper@verizon.net> - 2012-08-07 08:37 -0400
                Re: Wrapping existing UNIX commands in C Neil Cerutti <neilc@norwich.edu> - 2012-08-07 13:04 +0000
                Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-08-07 12:57 -0700
                Re: Wrapping existing UNIX commands in C gazelle@shell.xmission.com (Kenny McCormack) - 2012-08-07 21:24 +0000
                Re: Wrapping existing UNIX commands in C Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-08 00:58 -0700
                Re: Wrapping existing UNIX commands in C "BartC" <bc@freeuk.com> - 2012-08-06 18:04 +0100
                Re: Wrapping existing UNIX commands in C gazelle@shell.xmission.com (Kenny McCormack) - 2012-08-06 18:24 +0000
                Re: Wrapping existing UNIX commands in C jgk@panix.com (Joe keane) - 2012-08-22 17:08 +0000
                Re: Wrapping existing UNIX commands in C James Kuyper <jameskuyper@verizon.net> - 2012-08-06 14:46 -0400
                Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-08-06 11:55 -0700
                Re: Wrapping existing UNIX commands in C James Kuyper <jameskuyper@verizon.net> - 2012-08-06 19:13 -0400
                Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-08-06 11:50 -0700
                Re: Wrapping existing UNIX commands in C "BartC" <bc@freeuk.com> - 2012-08-06 20:28 +0100
                Re: Wrapping existing UNIX commands in C James Kuyper <jameskuyper@verizon.net> - 2012-08-06 15:44 -0400
                Re: Wrapping existing UNIX commands in C Robert Miles <milesrf@Usenet-News.net> - 2012-09-09 22:46 -0500
                Re: Wrapping existing UNIX commands in C Kaz Kylheku <kaz@kylheku.com> - 2012-09-10 04:29 +0000
                Re: Wrapping existing UNIX commands in C Keith Thompson <kst-u@mib.org> - 2012-09-09 22:42 -0700
                Re: Wrapping existing UNIX commands in C Kaz Kylheku <kaz@kylheku.com> - 2012-09-10 19:15 +0000
                Re: Wrapping existing UNIX commands in C pete <pfiland@mindspring.com> - 2012-09-10 22:25 -0400
                Re: Wrapping existing UNIX commands in C Öö Tiib <ootiib@hot.ee> - 2012-09-10 03:10 -0700
                Re: Wrapping existing UNIX commands in C James Kuyper <jameskuyper@verizon.net> - 2012-09-10 08:01 -0400
                Re: Wrapping existing UNIX commands in C "io_x" <a@b.c.invalid> - 2012-08-07 10:22 +0200
                Re: Wrapping existing UNIX commands in C "China Blue [Tor], Meersburg" <chine.bleu@yahoo.com> - 2012-08-07 01:55 -0700
                Re: Wrapping existing UNIX commands in C gazelle@shell.xmission.com (Kenny McCormack) - 2012-08-07 21:26 +0000
                Re: Wrapping existing UNIX commands in C Rui Maciel <rui.maciel@gmail.com> - 2012-08-08 08:47 +0100
                Re: Wrapping existing UNIX commands in C "Ansel" <tinker454@trytospammenowloser.com> - 2012-08-10 21:58 -0600
                Re: Wrapping existing UNIX commands in C Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-08-07 00:07 -0700
          Re: Wrapping existing UNIX commands in C Kenneth Brody <kenbrody@spamcop.net> - 2012-08-02 11:27 -0400
      Re: Wrapping existing UNIX commands in C Rui Maciel <rui.maciel@gmail.com> - 2012-08-16 09:43 +0100

csiph-web