r/C_Programming • • Jun 05 '26

Shellbonacci

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char ** argv)
{
  if(argc < 2)
    return 0;

  int n = atoi(argv[1]);

  if(n >= 2)
  {
    char bfr1[1000], bfr2[1000];

    sprintf(bfr1, "%s %d", argv[0], n - 1);
    sprintf(bfr2, "%s %d", argv[0], n - 2);

    n = system(bfr1) + system(bfr2);
  }
  
  printf("%d\n", n);

  return n;
}
13 Upvotes

16 comments sorted by

View all comments

Show parent comment

2

u/Dmxk Jun 06 '26

Nothing that doesn't depend on /proc i think. And depending on what environment you're running in, you might not be able to invoke yourself (jailed, in a security namespace etc)