title: What is the vulnerability in this C code?
body: <p>I'm trying to understand buffer overflow attacks better, this is one of the exercises that came up, that has a buffer overflow vulnerability. I would like to know how one can exploit the vulnerability in this code.
  I wasn't sure how to search for it.</p>
  
  <pre><code>int
  main(int argc, char **argv)
  {
      (void) foo(argv[1]);
      exit(0);
  }
  
  int
  foo(char *arg)
  {
      return bar(arg);
  }
  
  int
  bar(char *arg)
  {
      char lbuf[1024];
      if (strlen(arg) &gt;= 1024)
          return -1;
  
      memset(lbuf, 0, sizeof(lbuf));
      sprintf(lbuf, "%s", "Welcome: ");
      read(0, lbuf + strlen(lbuf), sizeof(lbuf) - strlen(lbuf) - 1);
      printf(lbuf);
      fflush(stdout);
  
      return 0;
  }
  </code></pre>