You are viewing a single comment's thread from:

RE: C Program to Run External Command using System (Synchronous)

in #programming5 years ago

Do not forget to mention that system 1) fork the shell (/bin/sh on nix systems) and 2) it can be a security risk and shouldn't be used lightheartly...

An interesting fact about sprintf is that it returns the number of bytes actually written. Hence the concatenation loop could look like:

      for (int i = 1; i < argc; ++i) {
                s += sprintf(buf + s, "%s ", argv[i]);
        }

An extra space will be written at the end of the buffer, and there's no check for buffer overflow (another security risk), as in your version.

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.081
BTC 59524.83
ETH 1569.75
USDT 1.00
SBD 0.42