text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE114_Process_Control__w32_char_relativePath_51a.c
  Label Definition File: CWE114_Process_Control__w32.label.xml
  Template File: sources-sink-51a.tmpl.c
  */
  /*
   * @description
   * CWE: 114 Process Control
   * BadSource: relativePath Hard code the relative pathname to the library
   * GoodSource: Hard code the full pathname to the library
   * Sink:
   *    BadSink : Load a dynamic link library
   * Flow Variant: 51 Data flow: data passed as an argument from one function to another in different source files
   *
   * */
  
  #include "std_testcase.h"
  
  #include <wchar.h>
  
  #include <windows.h>
  
  #ifndef OMITBAD
  
  /* bad function declaration */
  void CWE114_Process_Control__w32_char_relativePath_51b_bad_sink(char * data);
  
  void CWE114_Process_Control__w32_char_relativePath_51_bad()
  {
      char * data;
      char data_buf[100] = "";
      data = data_buf;
      /* FLAW: Specify just the file name for the library, not the full path */
      strcpy(data, "winsrv.dll");
      CWE114_Process_Control__w32_char_relativePath_51b_bad_sink(data);
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* good function declarations */
  void CWE114_Process_Control__w32_char_relativePath_51b_goodG2B_sink(char * data);
  
  /* goodG2B uses the GoodSource with the BadSink */
  static void goodG2B()
  {
      char * data;
      char data_buf[100] = "";
      data = data_buf;
      /* FIX: Specify the full pathname for the library */
      strcpy(data, "C:\\Windows\\System32\\winsrv.dll");
      CWE114_Process_Control__w32_char_relativePath_51b_goodG2B_sink(data);
  }
  
  void CWE114_Process_Control__w32_char_relativePath_51_good()
  {
      goodG2B();
  }
  
  #endif /* OMITGOOD */
  
  /* Below is the main(). It is only used when building this testcase on
     its own for testing or for building a binary to use in testing binary
     analysis tools. It is not used when compiling all the testcases as one
     application, which is how source code analysis tools are tested. */
  
  #ifdef INCLUDEMAIN
  
  int main(int argc, char * argv[])
  {
      /* seed randomness */
      srand( (unsigned)time(NULL) );
  #ifndef OMITGOOD
      printLine("Calling good()...");
      CWE114_Process_Control__w32_char_relativePath_51_good();
      printLine("Finished good()");
  #endif /* OMITGOOD */
  #ifndef OMITBAD
      printLine("Calling bad()...");
      CWE114_Process_Control__w32_char_relativePath_51_bad();
      printLine("Finished bad()");
  #endif /* OMITBAD */
      return 0;
  }
  
  #endif
  