text: /* TEMPLATE GENERATED TESTCASE FILE
  Filename: CWE114_Process_Control__w32_wchar_t_file_51b.c
  Label Definition File: CWE114_Process_Control__w32.label.xml
  Template File: sources-sink-51b.tmpl.c
  */
  /*
   * @description
   * CWE: 114 Process Control
   * BadSource: file Read input from a file
   * 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>
  
  #ifdef _WIN32
  #define FILENAME "C:\\temp\\file.txt"
  #else
  #define FILENAME "/tmp/file.txt"
  #endif
  
  #include <windows.h>
  
  /* all the sinks are the same, we just want to know where the hit originated if a tool flags one */
  
  #ifndef OMITBAD
  
  void CWE114_Process_Control__w32_wchar_t_file_51b_badSink(wchar_t * data)
  {
      {
          HMODULE hModule;
          /* POTENTIAL FLAW: If the path to the library is not specified, an attacker may be able to
           * replace his own file with the intended library */
          hModule = LoadLibraryW(data);
          if (hModule != NULL)
          {
              FreeLibrary(hModule);
              printLine("Library loaded and freed successfully");
          }
          else
          {
              printLine("Unable to load library");
          }
      }
  }
  
  #endif /* OMITBAD */
  
  #ifndef OMITGOOD
  
  /* goodG2B uses the GoodSource with the BadSink */
  void CWE114_Process_Control__w32_wchar_t_file_51b_goodG2BSink(wchar_t * data)
  {
      {
          HMODULE hModule;
          /* POTENTIAL FLAW: If the path to the library is not specified, an attacker may be able to
           * replace his own file with the intended library */
          hModule = LoadLibraryW(data);
          if (hModule != NULL)
          {
              FreeLibrary(hModule);
              printLine("Library loaded and freed successfully");
          }
          else
          {
              printLine("Unable to load library");
          }
      }
  }
  
  #endif /* OMITGOOD */
  