You are viewing a single comment's thread from:

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

in #programming3 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.15
TRX 0.17
JST 0.028
BTC 68761.82
ETH 2460.81
USDT 1.00
SBD 2.38