/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(void * dataVoidPtr)
{
    /* cast void pointer to a pointer of the appropriate type */
    wchar_t * * dataPtr = (wchar_t * *)dataVoidPtr;
    /* dereference dataPtr into data */
    wchar_t * data = (*dataPtr);
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, L"wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
void CWE36_Absolute_Path_Traversal__char_file_fopen_82_bad::action(char * data)
{
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, "wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
CWE36_Absolute_Path_Traversal__wchar_t_file_fopen_84_bad::~CWE36_Absolute_Path_Traversal__wchar_t_file_fopen_84_bad()
{
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, L"wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
Пример #4
0
void cu_difftext(char *testFile, char *referenceFile, char *exceptFile)
{
  char line[1024], tLine[1024], rLine[1024];
  int ii, nExcept = 0;

  // Read exceptions
  FILE *fp = FOPEN(exceptFile, "r");
  while(fgets(line, 1024, fp)) {
    chomp(line);
    nExcept++;
  }
  FCLOSE(fp);
  char **exception = (char **) MALLOC(sizeof(char *)*nExcept);
  fp = FOPEN(exceptFile, "r");
  for (ii=0; ii<nExcept; ii++) {
    exception[ii] = (char *) MALLOC(sizeof(char)*1024);
    fgets(exception[ii], 1024, fp);
  }
  FCLOSE(fp);

  // Go through both text files simultaneously
  FILE *fpTest = FOPEN(testFile, "r");
  FILE *fpRef = FOPEN(referenceFile, "r");
  while (fgets(tLine, 1024, fpTest)) {
    fgets(rLine, 1024, fpRef);
    for (ii=0; ii<nExcept; ii++) {
      if (strcmp_case(rLine, exception[ii]) != 0) {
	if (strcmp_case(tLine, rLine) != 0) {
	  asfForcePrintStatus("\ntest: %sreference: %s", tLine, rLine);
	  CU_ASSERT_TRUE(strcmp_case(tLine, rLine) == 0);
	}
      }
    }
  }

  // Clean up
  for (ii=0; ii<nExcept; ii++)
    FREE(exception[ii]);
  FREE(exception);
}
void badSink(char * * dataPtr)
{
    char * data = *dataPtr;
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, "wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(list<wchar_t *> dataList)
{
    wchar_t * data = dataList.back();
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, L"wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
Пример #7
0
static void addDebugLine(_In_z_ _Printf_format_string_ TCHAR const * const format, ...) {
  static Semaphore gate;
  static TCHAR *mode = _T("w");
  gate.wait();
  FILE *f = FOPEN(_T("c:\\temp\\semaphore.log"),mode);
  mode = _T("a");
  va_list argptr;
  va_start(argptr,format);
  _vftprintf(f, format, argptr);
  va_end(argptr);
  fclose(f);
  gate.signal();
}
static void badSink()
{
    wchar_t * data = badData;
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, L"wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(vector<char *> dataVector)
{
    char * data = dataVector[2];
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, "wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
void badSink()
{
    char * data = CWE36_Absolute_Path_Traversal__char_console_fopen_68_badData;
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, "wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(map<int, wchar_t *> dataMap)
{
    wchar_t * data = dataMap[2];
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, L"wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
/* goodG2B() uses the GoodSource with the BadSink */
static void goodG2BSink()
{
    char * data = goodG2BData;
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, "wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink()
{
    wchar_t * data = CWE36_Absolute_Path_Traversal__wchar_t_connect_socket_fopen_68_goodG2BData;
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, L"wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink(structType myStruct)
{
    wchar_t * data = myStruct.structFirst;
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, L"wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
Пример #15
0
void getSignalFormat(char *baseName,long long bytesInFile,getRec *r)
{
    char name[1024];
    char buf[80];
    FILE *fp;
    create_name(name,baseName,".fmt");
    fp=FOPEN(name,"r");
    FILL(buf,80,fp) sscanf(buf,"%i%i", &r->lineSize, &r->header);
    FILL(buf,80,fp) sscanf(buf,"%f%f", &r->dcOffsetI, &r->dcOffsetQ);
    FILL(buf,80,fp) sscanf(buf,"%c", &r->flipIQ);

    r->nLines=bytesInFile/r->lineSize;/*Automatically figure out number of lines in file.*/
    r->nSamples=(r->lineSize-r->header)/r->sampleSize;/*Ditto for samples*/

    fgets(buf,80,fp);/*Skip comment line*/
    if (NULL==fgets(buf,80,fp))
        return; /*If no extra data, bail!*/
    else /*File has information about window shifts and AGC compensation*/
    {/*Read infomation about each line of the file*/
        float firstWindow;/*First Window Position shift*/
        int lastLine;float lastAGC,lastWindow;
        int keepGoing=1;

        r->lines=(signalLineRec *)MALLOC(r->nLines*sizeof(signalLineRec));

        /*Read first line's info.*/
        sscanf(buf,"%d%g%g",&lastLine,&lastWindow,&lastAGC);
        firstWindow=lastWindow;

        while (keepGoing)
        {
            int line,thisLine;
            if (NULL==fgets(buf,80,fp))
            {/*Hit EOF*/
                keepGoing=0;/*Don't keep going*/
                thisLine=r->nLines;/*Write to last line*/
            } else
                sscanf(buf,"%d",&thisLine);

            /*Write old values until this line*/
            for (line=lastLine;line<thisLine;line++)
            {
                r->lines[line].shiftBy=(int)(lastWindow-firstWindow);
                r->lines[line].scaleBy=lastAGC;
            }
            /*Read new values*/
            sscanf(buf,"%d%g%g",&lastLine,&lastWindow,&lastAGC);
        }
    }
    fclose(fp);
}
Пример #16
0
/**
 * Write PID file.
 *
 * @param sctx service context
 * @param pid PID to write (should be equal to 'getpid()'
 * @return  #GNUNET_OK on success (including no work to be done)
 */
static int
write_pid_file (struct GNUNET_SERVICE_Context *sctx, pid_t pid)
{
  FILE *pidfd;
  char *pif;
  char *user;
  char *rdir;
  int len;

  if (NULL == (pif = get_pid_file_name (sctx)))
    return GNUNET_OK;           /* no file desired */
  user = get_user_name (sctx);
  rdir = GNUNET_strdup (pif);
  len = strlen (rdir);
  while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
    len--;
  rdir[len] = '\0';
  if (0 != ACCESS (rdir, F_OK))
  {
    /* we get to create a directory -- and claim it
     * as ours! */
    (void) GNUNET_DISK_directory_create (rdir);
    if ((NULL != user) && (0 < strlen (user)))
      GNUNET_DISK_file_change_owner (rdir, user);
  }
  if (0 != ACCESS (rdir, W_OK | X_OK))
  {
    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir);
    GNUNET_free (rdir);
    GNUNET_free_non_null (user);
    GNUNET_free (pif);
    return GNUNET_SYSERR;
  }
  GNUNET_free (rdir);
  pidfd = FOPEN (pif, "w");
  if (NULL == pidfd)
  {
    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
    GNUNET_free (pif);
    GNUNET_free_non_null (user);
    return GNUNET_SYSERR;
  }
  if (0 > FPRINTF (pidfd, "%u", pid))
    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
  GNUNET_break (0 == FCLOSE (pidfd));
  if ((NULL != user) && (0 < strlen (user)))
    GNUNET_DISK_file_change_owner (pif, user);
  GNUNET_free_non_null (user);
  GNUNET_free (pif);
  return GNUNET_OK;
}
Пример #17
0
const CHR *AudioIO::detectSourceType(const CHR *const fileName, const bool verbose)
{
	if (verbose)
	{
		PRINT_NFO(TXT("------- Audio I/O -------"));
	}
	
	uint8_t type = AUDIO_LIB_NULL;
	const bool bStdIn = (STRCASECMP(fileName, TXT("-")) == 0);

	if (bStdIn || PATH_ISREG(fileName))
	{
		if (FILE *const file = bStdIn ? stdin : FOPEN(fileName, TXT("rb")))
		{
			if (FD_ISREG(FILENO(file)))
			{
				for (size_t i = 0; g_audioIO_mapping[i].id; ++i)
				{
					if (verbose)
					{
						PRINT2_NFO(TXT("Trying input module ") FMT_CHR TXT("..."), g_audioIO_mapping[i].name);
					}
					if (checkFileType(g_audioIO_mapping[i].checkFileType, file))
					{
						type = g_audioIO_mapping[i].id;
						if (verbose)
						{
							PRINT_NFO(TXT("succeeded."));
						}
						break;
					}
				}
			}
			if (!bStdIn)
			{
				fclose(file);
			}
		}
	}

	if (verbose)
	{
		if(type == AUDIO_LIB_NULL)
		{
			PRINT_NFO(TXT("No suitable input module found -> falling back to default!"));
		}
		PRINT_NFO(TXT("------- Audio I/O -------\n"));
	}

	return getLibName(type);
}
Пример #18
0
int asf_logscale(const char *inFile, const char *outFile)
{
  int ii, jj, kk;
  meta_parameters *meta = meta_read(inFile);
  int band_count = meta->general->band_count;
  int sample_count = meta->general->sample_count;
  int line_count = meta->general->line_count;
  float *bufIn = (float *) MALLOC(sizeof(float)*sample_count);
  float *bufOut = (float *) MALLOC(sizeof(float)*sample_count);
  
  char *input = appendExt(inFile, ".img");
  char *output = appendExt(outFile, ".img");
  FILE *fpIn = FOPEN(input, "rb");
  FILE *fpOut = FOPEN(output, "wb");
  for (kk=0; kk<band_count; kk++) {
    for (ii=0; ii<line_count; ii++) {
      get_band_float_line(fpIn, meta, kk, ii, bufIn);
      for (jj=0; jj<sample_count; jj++) {
	if (FLOAT_EQUIVALENT(bufIn[jj], 0.0))
	  bufOut[jj] = 0.0;
	else
	  bufOut[jj] = 10.0 * log10(bufIn[jj]);
      }
      put_band_float_line(fpOut, meta, kk, ii, bufOut);
      asfLineMeter(ii, line_count);
    }
  }
  meta_write(meta, outFile);
  meta_free(meta);
  FCLOSE(fpIn);
  FCLOSE(fpOut);
  FREE(bufIn);
  FREE(bufOut);
  FREE(input);
  FREE(output);

  return FALSE;
}
void badSink(map<int, char *> dataMap)
{
    /* copy data out of dataMap */
    char * data = dataMap[2];
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, "wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
void badSink(vector<wchar_t *> dataVector)
{
    /* copy data out of dataVector */
    wchar_t * data = dataVector[2];
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, L"wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
void bad()
{
    wchar_t * data;
    wchar_t dataBuffer[FILENAME_MAX] = L"";
    data = dataBuffer;
    if(globalReturnsTrueOrFalse())
    {
        {
            /* Read input from a file */
            size_t dataLen = wcslen(data);
            FILE * pFile;
            /* if there is room in data, attempt to read the input from a file */
            if (FILENAME_MAX-dataLen > 1)
            {
                pFile = fopen(FILENAME, "r");
                if (pFile != NULL)
                {
                    /* POTENTIAL FLAW: Read data from a file */
                    if (fgetws(data+dataLen, (int)(FILENAME_MAX-dataLen), pFile) == NULL)
                    {
                        printLine("fgetws() failed");
                        /* Restore NUL terminator if fgetws fails */
                        data[dataLen] = L'\0';
                    }
                    fclose(pFile);
                }
            }
        }
    }
    else
    {
#ifdef _WIN32
        /* FIX: Use a fixed, full path and file name */
        wcscat(data, L"c:\\temp\\file.txt");
#else
        /* FIX: Use a fixed, full path and file name */
        wcscat(data, L"/tmp/file.txt");
#endif
    }
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, L"wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
Пример #22
0
// Main program body.
int
main (int argc, char *argv[])
{
  int currArg = 1;
  int NUM_ARGS = 4;

  handle_license_and_version_args(argc, argv, ASF_NAME_STRING);
  asfSplashScreen(argc, argv);

  if (argc >= 2 && strmatches(argv[1],"-help","--help",NULL))
    print_help();
  if (argc<3)
    rtc_usage(ASF_NAME_STRING);

  while (currArg < (argc-NUM_ARGS)) {
    char *key = argv[currArg++];
    if (strmatches(key,"-help","--help",NULL)) {
        print_help(); // doesn't return
    }
    else if (strmatches(key,"-log","--log",NULL)) {
      CHECK_ARG(1);
      strncpy_safe(logFile,GET_ARG(1),256);
      fLog = FOPEN(logFile, "a");
      logflag = TRUE;
    }
    else if (strmatches(key,"-quiet","--quiet","-q",NULL)) {
      quietflag = TRUE;
    }
    else {
      --currArg;
      break;
    }
  }

  if ((argc-currArg) < NUM_ARGS) {
    printf("Insufficient arguments.  Expected %d, got %d.\n",
           NUM_ARGS, argc-currArg);
    rtc_usage(argv[0]);
  } else if ((argc-currArg) > NUM_ARGS) {
    printf("Unknown argument: %s\n", argv[currArg]);
    rtc_usage(argv[0]);
  }

  int fail = uavsar_rtc(argv[currArg], argv[currArg+1], argv[currArg+2],
                        argv[currArg+3]);

  asfPrintStatus(fail ? "Failed.\n" : "Done.\n");
  return fail ? EXIT_FAILURE : EXIT_SUCCESS;
}
static int
init ()
{
#if LOG_BACKOFF
  killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log");
  if (NULL == (killLogFilePtr = FOPEN (killLogFileName, "w")))
    {
      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen",
				killLogFileName);
      GNUNET_free (killLogFileName);
      return GNUNET_SYSERR;
    }
#endif
  return GNUNET_OK;
}
void bad()
{
    wchar_t * data;
    wchar_t dataBuffer[FILENAME_MAX] = L"";
    data = dataBuffer;
    data = badSource(data);
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, L"wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
Пример #25
0
static int
testFileHash ()
{
  int ret;
  FILE *f;

  memset (block, 42, sizeof (block) / 2);
  memset (&block[sizeof (block) / 2], 43, sizeof (block) / 2);
  GNUNET_assert (NULL != (f = FOPEN (FILENAME, "w+")));
  GNUNET_break (sizeof (block) == fwrite (block, 1, sizeof (block), f));
  GNUNET_break (0 == FCLOSE (f));
  ret = 1;
  GNUNET_SCHEDULER_run (&file_hasher, &ret);
  GNUNET_break (0 == UNLINK (FILENAME));
  return ret;
}
Пример #26
0
void 
loadWrappedPhase(char *f)
{
  FILE * fd;
  meta_parameters *meta;

  printf ("   loading wrapped phase...\n");

  fd = FOPEN(f, "rb");
  meta = meta_read(f);
  get_float_lines(fd, meta, 0, len, phase);
  FCLOSE(fd);

  printf("   wrapped phase data loaded...\n");
  return;
}
static void goodG2B()
{
    char * data;
    char dataBuffer[FILENAME_MAX] = BASEPATH;
    data = dataBuffer;
    goodG2BSource(data);
    {
        FILE *pFile = NULL;
        /* POTENTIAL FLAW: Possibly opening a file without validating the file name or path */
        pFile = FOPEN(data, "wb+");
        if (pFile != NULL)
        {
            fclose(pFile);
        }
    }
}
void ByteStringExtractor::extractStrings(const TCHAR *fname) {
  FILE *f = FOPEN(fname, _T("rb"));
  setvbuf(f, NULL, _IOFBF, 0x10000);

  int ch;
  m_strLength = 0;
  while((ch = fgetc(f)) != EOF) {
    if(ISALPHA(ch)) {
      appendChar(ch);
    } else {
      outputString();
    }
  }
  outputString();
  fclose(f);
}
Пример #29
0
static char *findInArcList(char *acquisition_time, char *arclist)
{
    char line[1024];
    char *odr = NULL;

    // ODR files will be in the same directory as arclist
    char *dir = get_dirname(arclist);

    FILE *fp = FOPEN(arclist, "r");
    if (!fp) {
        asfPrintError("Failed to open: %s\n", arclist);
    }

    ymd_date ymd;
    hms_time hms;

    parse_DMYdate(acquisition_time, &ymd, &hms);

    // YYYYMMDD as an integer
    int scene_time = ymd.year * 10000 + ymd.month * 100 + ymd.day;

    while (fgets(line, 1024, fp) != NULL) {
        if (isdigit(line[0])) {
            int arc, start, end, junk, n;
            n = sscanf(line, "%d  %d %d:%d - %d %d:%d",
                       &arc, &start, &junk, &junk, &end, &junk, &junk);
            start = arclist_time_fudge(start);
            end = arclist_time_fudge(end);
            if (n == 7) {
                if (scene_time > start && scene_time < end) {
                    odr = MALLOC(sizeof(char)*(strlen(dir)+64));
                    sprintf(odr, "%sODR.%03d", dir, arc);
                    break;
                }
            }
        }
    }

    FCLOSE(fp);

    if (!odr)
        odr = STRDUP("");

    FREE(dir);
    return odr;
}
Пример #30
-2
latan_errno plot_save(const strbuf dirname, plot *p)
{
    strbuf path,buf,*datfname_bak,term_bak,output_bak;
    FILE *outf;
    size_t i,j,lc;
    mode_t mode_755;
    strbuf name,ver,err_msg;
    
    MALLOC_ERRVAL(datfname_bak,strbuf *,p->nplot,LATAN_ENOMEM);
    
    mode_755 = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
    
    /* backup I/O parameters */
    strbufcpy(term_bak,p->term);
    strbufcpy(output_bak,p->output);
    for (i=0;i<p->nplot;i++)
    {
        strbufcpy(datfname_bak[i],p->datfname[i]);
    }
    /* generate directory */
    if (access(dirname,R_OK|W_OK|X_OK))
    {
        if (mkdir(dirname,mode_755))
        {
            sprintf(err_msg,"impossible to create directory %s",dirname);
            LATAN_ERROR(err_msg,LATAN_ESYSTEM);
        }
    }
    /* save pdf */
    sprintf(path,"%s/plot.pdf",dirname);
    plot_set_term(p,"pdf");
    plot_set_output(p,path);
    plot_disp(p);
    plot_set_term(p,term_bak);
    plot_set_output(p,output_bak);
    /* save script and datafiles */
    j = 0;
    for (i=0;i<p->nplot;i++)
    {
        if (strlen(p->datfname[i]))
        {
            sprintf(p->datfname[i],"points_%lu.dat",(long unsigned)(j));
            j++;
            sprintf(path,"%s/%s",dirname,p->datfname[i]);
            FOPEN(outf,path,"w");
            BEGIN_FOR_LINE(buf,datfname_bak[i],lc)
            {
                fprintf(outf,"%s\n",buf);
            }
            END_FOR_LINE
            fclose(outf);
        }