Example #1
0
/**
 * Main function
 * \brief Main function
 * \param argc  A count of the number of command-line arguments
 * \param argv  An argument vector of the command-line arguments.
 * \warning Must be called with two filenames patchFile, originalFile as commandline parameters and in the given order.
 * \returns { 0 if succeeds, exit code otherwise}
 */
int main (int argc, char *argv[]) {
    FILE *patchFile;
    FILE *originalFile;

    if(argc<3) {
        fprintf(stderr, "!!!!! Usage: ./applyPatch patchFile originalFile !!!!!\n");
        exit(EXIT_FAILURE); /* indicate failure.*/
    }

    patchFile = fopen(argv[1] , "r" );
    originalFile = fopen(argv[2] , "r" );

    if (patchFile==NULL) {
        fprintf(stderr, "!!!!! Error opening patchFile !!!!! \n");
        exit(EXIT_FAILURE);
    }
    if (originalFile==NULL) {
        fprintf (stderr, "!!!!! Error opening originalFile !!!!!\n");
        exit(EXIT_FAILURE);
    }

    applyPatch(patchFile, originalFile);

    fclose(patchFile);
    fclose(originalFile);
    return 0;
}
static void panoMenderDuplicateScriptFile(char *scriptFileName, char *script, fullPath  *scriptPathName)
{
    FILE* scriptFD;
    int temp;
    
    strcpy(scriptPathName->name, scriptFileName);
      
    // Get a temp filename for the copy of the script
    if (panoFileMakeTemp(scriptPathName) == 0) {
        PrintError("Could not make Tempfile");
        exit(1);
    }
    
    // Copy the script
    if ((scriptFD = fopen(scriptPathName->name, "w")) == NULL) {
        PrintError("Could not open temporary Scriptfile");
        exit(1);
    }
    
    temp = fwrite(script, 1, (int) strlen(script), scriptFD); 
    
    if (strlen(script) != temp) {
        PrintError("Could not write temporary Scriptfile");
        exit(1);
    }
    
    fclose(scriptFD);
    
}
Example #3
0
char *
TimeString (time_t start, time_t end)
{
  static char datestr[255];
  char t1[64], t2[64];
  struct tm *tbuff;

  if (start)
    {
      tbuff = localtime (&start);
      if (!tbuff)
	{
	  perror ("Error time convert");
	  exit (250);
	}
      strftime (t1, 63, "%Y-%m-%d %H:%M:%S", tbuff);

      tbuff = localtime (&end);
      if (!tbuff)
	{
	  perror ("Error time convert");
	  exit (250);
	}
      strftime (t2, 63, "%Y-%m-%d %H:%M:%S", tbuff);

      snprintf (datestr, 254, "%s - %s", t1, t2);
    }
  else
    {
      snprintf (datestr, 254, "Time Window unknown");
    }
  datestr[254] = 0;
  return datestr;
}
Example #4
0
int royparse_start(logerr_t* a_logerr)
{
    logerr = a_logerr;

    if (opt_q) {
        pcap  = pcap_open_dead(DLT_RAW, 65535);
        q_out = pcap_dump_open(pcap, opt_q);
        if (q_out == 0) {
            logerr("%s: %s\n", opt_q, strerror(errno));
            exit(1);
        }
    }
    if (opt_r) {
        r_out = fopen(opt_r, "w");
        if (r_out == 0) {
            logerr("%s: %s\n", opt_r, strerror(errno));
            exit(1);
        }
    } else {
        r_out = stdout;
    }
    setbuf(r_out, 0);

    return 0;
}
Example #5
0
void check_page(unsigned char *data,const int *header,ogg_page *og){
  long j;
  /* Test data */
  for(j=0;j<og->body_len;j++)
    if(og->body[j]!=data[j]){
      fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
	      j,data[j],og->body[j]);
      exit(1);
    }

  /* Test header */
  for(j=0;j<og->header_len;j++){
    if(og->header[j]!=header[j]){
      fprintf(stderr,"header content mismatch at pos %ld:\n",j);
      for(j=0;j<header[26]+27;j++)
	fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
      fprintf(stderr,"\n");
      exit(1);
    }
  }
  if(og->header_len!=header[26]+27){
    fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
	    og->header_len,header[26]+27);
    exit(1);
  }
}
Example #6
0
int
get_next_index( simple_reader * sri, const int last_index )
{
    int index, check;
    char *iline = NULL;

    while( sr_readline( sri ) ) {
        iline = sr_line( sri );
        if( sr_line_isempty( sri ) )
            continue;
        if( '#' == iline[0] )
            continue;
        break;
    }

    if( sr_eof( sri ) || NULL == iline )
        return -1;

    check = sscanf( iline, "%d", &index );
    if( check != 1 ) {
        fprintf( stderr, "ERROR: could not read index on line %d of %s\n",
                 sr_linenum( sri ), sr_filename( sri ) );
        exit( EXIT_FAILURE );
    }

    if( index <= 0 || index <= last_index ) {
        fprintf( stderr, "ERROR: bad index on line %d of %s\n",
                 sr_linenum( sri ), sr_filename( sri ) );
        fprintf( stderr, "  -> INDEX must be positive non-zero and monotonically increasing\n" );
        exit( EXIT_FAILURE );
    }

    return index;
}
Example #7
0
void setuser(const char *user)
{
	uid_t uid;

	if (!strlen(user)) {
		return;
	}

	if (getuid() != 0 && geteuid() != 0) {
		printf("Error: User can only be set as root.\n");
		exit(EXIT_FAILURE);
	}

	if (isnumeric(user) && atoi(user) == 0) {
		return;
	}

	uid = getuser(user);

	if (debug)
		printf("switching to user id %d.\n", uid);

	if (setuid(uid) != 0) {
		perror("Error: setuid");
		exit(EXIT_FAILURE);
	}
}
Example #8
0
File: bti.c Project: thesues/bti
static int find_urls(const char *tweet, int **pranges)
{
	/*
	 * magic obtained from
	 * http://www.geekpedia.com/KB65_How-to-validate-an-URL-using-RegEx-in-Csharp.html
	 */
	static const char *re_magic =
	    "(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)/{1,3}"
	    "[0-9a-zA-Z;/~?:@&=+$\\.\\-_'()%]+)"
	    "(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?";
	pcre *re;
	const char *errptr;
	int erroffset;
	int ovector[10] = { 0, };
	const size_t ovsize = sizeof(ovector) / sizeof(*ovector);
	int startoffset, tweetlen;
	int i, rc;
	int rbound = 10;
	int rcount = 0;
	int *ranges = malloc(sizeof(int) * rbound);

	re = pcre_compile(re_magic,
			  PCRE_NO_AUTO_CAPTURE, &errptr, &erroffset, NULL);
	if (!re) {
		fprintf(stderr, "pcre_compile @%u: %s\n", erroffset, errptr);
		exit(1);
	}

	tweetlen = strlen(tweet);
	for (startoffset = 0; startoffset < tweetlen;) {

		rc = pcre_exec(re, NULL, tweet, strlen(tweet), startoffset, 0,
			       ovector, ovsize);
		if (rc == PCRE_ERROR_NOMATCH)
			break;

		if (rc < 0) {
			fprintf(stderr, "pcre_exec @%u: %s\n",
				erroffset, errptr);
			exit(1);
		}

		for (i = 0; i < rc; i += 2) {
			if ((rcount + 2) == rbound) {
				rbound *= 2;
				ranges = realloc(ranges, sizeof(int) * rbound);
			}

			ranges[rcount++] = ovector[i];
			ranges[rcount++] = ovector[i + 1];
		}

		startoffset = ovector[1];
	}

	pcre_free(re);

	*pranges = ranges;
	return rcount;
}
Example #9
0
void init_openssl()
{
    if (!RAND_status()) {
	time_t time_sec = time(NULL);
	if (time_sec == (time_t)-1) {
            perror("time() system call failed");
	    exit(EXIT_FAILURE);
	}
	RAND_seed(&time_sec, sizeof(time_sec));
    }
    while (!RAND_status()) {
#ifdef MINGW
	FILETIME filetime;
	GetSystemTimeAsFileTime(&filetime);
	RAND_seed(&filetime.dwLowDateTime, sizeof(filetime.dwLowDateTime));
#else
        struct timeval tv;
	if (gettimeofday(&tv, NULL) == -1) {
	    perror("gettimeofday() system call failed");
	    exit(EXIT_FAILURE);
        }
	RAND_seed(&tv.tv_usec, sizeof(tv.tv_usec));
#endif
    }
    ERR_load_crypto_strings();
    /* Random seeding in OpenSSL may use some system calls that fail.
     * We should ignore these error codes in future error messages. */
    errno = 0;
}
Example #10
0
GLFWwindow* initGLWindow() {
    GLFWwindow* window;
    
    glfwSetErrorCallback(error_callback);
    
    if (!glfwInit())
        exit(EXIT_FAILURE);
    
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    
    window = glfwCreateWindow(854, 480, "Simple example", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    
    glfwMakeContextCurrent(window);
    glfwSetKeyCallback(window, key_callback);
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
    
    // Initialize GLEW
    glewExperimental=true; // Needed in core profile
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        exit(EXIT_FAILURE);
    }
    
    return window;
}
Example #11
0
int main(int argc, char *argv[]) {

	int fd = open("crackme", O_RDONLY);

    if(fd == -1) {
        perror(NULL);
        exit(10);
    }

	struct stat st_fd;
    if(fstat(fd, &st_fd) == -1) {
        perror(NULL);
        exit(11);
    }

	void* ptr = mmap(NULL, st_fd.st_size,
		PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0
	);

	int (*func)(char* str) = (ptr + 0xea0);


	int ret = func(argv[1]);
	printf("%x\n", ret);
	return 0;
}
Example #12
0
void udp_server::init()
{
	_sock = socket(AF_INET, SOCK_DGRAM, 0);
	if (_sock < 0)
	{
		print_log("create socket error!", __FUNCTION__, __LINE__);
		exit(1);		
	}

	struct sockaddr_in local;
	socklen_t len = sizeof(local);
	local.sin_family = AF_INET;
	local.sin_port = htons(_port);
	if (_ip == "any")
	{
		local.sin_addr.s_addr = htons(INADDR_ANY);
	}
	else
	{
		local.sin_addr.s_addr = inet_addr(_ip.c_str());
	}

	if (bind(_sock, (struct sockaddr *)&local, len) < 0)
	{
		print_log(strerror(errno), __FUNCTION__, __LINE__);
		exit(2);
	}
}
Example #13
0
int adb_main()
{
    atexit(adb_cleanup);
#if defined(HAVE_FORKEXEC)
    // No SIGCHLD. Let the service subproc handle its children.
    signal(SIGPIPE, SIG_IGN);
#endif

    init_transport_registration();

    // The minimal version of adbd only uses USB.
    if (access("/dev/android_adb", F_OK) == 0) {
        // listen on USB
        usb_init();
    }

    if (setgid(AID_SHELL) != 0) {
        fprintf(stderr, "failed to setgid to shell\n");
        exit(1);
    }
    if (setuid(AID_SHELL) != 0) {
        fprintf(stderr, "failed to setuid to shell\n");
        exit(1);
    }
    fprintf(stderr, "userid is %d\n", getuid());

    D("Event loop starting\n");

    fdevent_loop();

    usb_cleanup();

    return 0;
}
Example #14
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:    function_types
 *  Description:    extract left and right types from the goal
 * =====================================================================================
 */
LOCAL void function_types(TYPE goal,TYPE * left, TYPE * right){

    // We have to check t1->t2
    switch(N(language)){
                    
        case SCHEME : {
            left->byte  = N(makeTIgnore)();
            right->byte = N(makeTIgnore)();
            break;
        }
                        
        case ML : {
            if(goal.a->t != N(TARROW)){
                DEBUG_PRINT("Closure requires arrow type");
                exit(1);
            }
            (*left)  = goal.a->left;
            (*right) = goal.a->right;
            break;
        }

        default :{
            DEBUG_PRINT("Language not supported");
            exit(1); 
        }
    }
}
Example #15
0
main()
{
    char c;
    int shmid;
    key_t key;
    int *shm, *s;

    key = 7000;
     printf("hei1");

    if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {
        perror("shmget");
        exit(1);
    }
        printf("hei2");
    if ((shm = shmat(shmid,0, 0666)) == NULL) {
        perror("shmat");
        exit(1);
    }

     s = shm;

    for (c = 'a'; c <= 'z'; c++)
        *s++ = c;
    *s = NULL;

		
    while (*shm != '*')
        sleep(1);

    exit(0);
}
Example #16
0
////////////////////////////  Normal functions //////////////////////////
//Func: argv_handler
//Determine what flag is being called from argv
//flags = [t | n | p | v | c | q ]
void argv_handler(int argc, char **argv, int *flags){
	char c;
	char *str;
	for(int i = 0; i < 6; ++i){
		flags[i] = 0;
	}
	while((c = getopt(argc, argv, "t:n:p:cqv"))!= -1){
		//FIXME: getopt causing me problem
		switch(c){
			case 't':
				str = optarg;
				flags[0] = atoi(str);
				break;
			case 'n':
				str = optarg;
				flags[1] = atoi(str);
				break;
			case 'p':
				str = optarg;
				flags[2] = atoi(str);
				break;
			case 'v':
				flags[3] = 1;
				break;
			case 'c':
				flags[4] = 1;
				break;
			case 'q':
				flags[5] = 1;
				break;
			case '?':
				if(optopt == 't' || optopt =='n' || optopt =='p')
					fprintf(stderr,"-%c requires an argument.\n",optopt);
				else
					fprintf(stderr,"Unknown option character -%c\n",optopt);
				return ;
			default:
				abort();
		}
	}
	if(flags[0] == 0 || flags[1] == 0 || flags[2] == 0){
		printf(YC"Error: Insufficient information\n"NC);
		printf(YC"Ex: ./sieve -t [time intev] -n [#obj] -p [#threads] [-cqv]\n"NC);
		exit(EXIT_FAILURE);
	}

	if(flags[0] <= 0 || flags[1] <= 0 || flags[2] <= 0){
		printf(YC"Error: #thread, #astr, #thread must not be a negative number\n"NC);
		printf(YC"Ex: ./sieve -t [time intev] -n [#obj] -p [#threads] [-cqv]\n"NC);
		exit(EXIT_FAILURE);
	}


	if(flags[2] > flags[1]){
		printf(YC"A number of particle must not be less than a number of threads\n"NC);
		exit(EXIT_FAILURE);

	}

}
Example #17
0
/*
 * Test the seek file operation on a file whose name is given as the first
 * argument.
 */
int main(int argc, char **argv) {

  int fd;
  int rc;

  if( argc != 2 ) {
    printf("usage: %s filename\n", argv[0]);
    exit(2);
  }

  fd = open(argv[1], O_RDONLY, 0);
 
  if(fd == -1) {
    perror("selinux_seek:open");
    exit(2);
  }

  rc = lseek(fd, 10, SEEK_SET);
  if( rc == -1 ) {
    perror("selinux_seek:lseek");
    close(fd);
    exit(1);
  }

  close(fd);
  exit(0);

}
Example #18
0
static void tx_fifo_sync(void)
{
#if 0
	int fd;
	int err;

	fd = open(CpuEmuCommDev.tx_fifo.path, O_WRONLY|O_BINARY);
	if (fd < 0) {
		printf("file open error:%s\n", CpuEmuCommDev.tx_fifo.path);
		exit(1);
	}
	err = lseek(fd, CpuEmuCommDev.tx_fifo.fileoff, SEEK_SET);
	if (err < 0) {
		printf("lseek error:%s\n", CpuEmuCommDev.tx_fifo.path);
		exit(1);
	}

	err = write(fd, CpuEmuCommDev.tx_fifo.buffer, CpuEmuCommDev.tx_fifo.size);
	if (err != CpuEmuCommDev.tx_fifo.size) {
		printf("write error:%s\n", CpuEmuCommDev.tx_fifo.path);
		exit(1);
	}
	CpuEmuCommDev.tx_fifo.fileoff += err;
	CpuEmuCommDev.tx_fifo.off = 0;
	CpuEmuCommDev.tx_fifo.size = 0;

	close(fd);
	return;
#endif
}
Example #19
0
static int do_compact(int argc, const char **argv)
{
   uint32_t duration;

   if (argc > 2)
   {
      if (strcmp(argv[2], "a") == 0)
      {
         mmal_vc_compact(MMAL_VC_COMPACT_AGGRESSIVE, &duration);
         printf("Triggered aggressive compaction on VC - duration %u us.\n", duration);
      }
      else if (strcmp(argv[2], "d") == 0)
      {
         mmal_vc_compact(MMAL_VC_COMPACT_DISCARD, &duration);
         printf("Triggered discard compaction on VC - duration %u us.\n", duration);
      }
      else if (strcmp(argv[2], "n") == 0)
      {
         mmal_vc_compact(MMAL_VC_COMPACT_NORMAL, &duration);
         printf("Triggered normal compaction on VC - duration %u us.\n", duration);
      }
      else
      {
         printf("Invalid memory compaction option %s\n.", argv[2]);
         exit(1);
      }
   }
   else
   {
      printf("Invalid memory compaction arguments.  Need to specify 'a', 'n' or 't'.\n");
      exit(1);
   }
   return 0;
}
static void
process_options(int argc, char *argv[])
{
    int opt;

    opterr = 0;
    while (-1 != (opt = getopt(argc, argv, "cdh"))) {
	switch (opt) {
	case 'c':
	    use_case_insensitive_compare = 1;
	    break;
	case 'd':
	    debug_enabled = 1;
	    break;
	case 'h':
	    usage(argv[0]);
	    exit(0);
	case '?':
	    opt = optopt;
	    /* fall thru to default */
	default:
	    warn("Unknown option: -%c\n\n", opt);
	    usage(argv[0]);
	    exit(1);
	    break;		/* not reached */
	}
    }
    return;
}
Example #21
0
void setgroup(const char *group)
{
	gid_t gid;

	if (!strlen(group)) {
		return;
	}

	if (getuid() != 0 && geteuid() != 0) {
		printf("Error: Group can only be set as root.\n");
		exit(EXIT_FAILURE);
	}

	if (isnumeric(group) && atoi(group) == 0) {
		return;
	}

	gid = getgroup(group);

	if (debug)
		printf("switching to group id %d.\n", gid);

	if (setgid(gid) != 0) {
		perror("Error: setgid");
		exit(EXIT_FAILURE);
	}
}
Example #22
0
static void setup()
{
    client = ccnet_client_new ();
    if ( ccnet_client_load_confdir(client, CCNET_DIR) < 0 ) {
        fprintf (stderr, "Read config dir error\n");
        exit(1);
    }

    event_init ();

    if (g_access (TEST_DIR "worktree", F_OK) != 0 &&
        g_mkdir (TEST_DIR "worktree", 0777) < 0) {
        fprintf (stderr, "Failed to create worktree.\n");
        exit (1);
    }

    seaf = seafile_session_new (SEAF_DIR, 
                                WORKTREE_DIR,
                                client);
    if (!seaf) {
        fprintf (stderr, "Failed to create seafile session.\n");
        exit (1);
    }
    seafile_session_prepare (seaf);
}
Example #23
0
void royparse_getopt(int* argc, char** argv[])
{
    int c;

    while ((c = getopt(*argc, *argv, "?q:r:")) != EOF) {
        switch (c) {
        case '?':
            royparse_usage();
            exit(1);
            break;
        case 'q':
            if (opt_q)
                free(opt_q);
            opt_q = strdup(optarg);
            break;
        case 'r':
            if (opt_r)
                free(opt_r);
            opt_r = strdup(optarg);
            break;
        default:
            royparse_usage();
            exit(1);
        }
    }
}
Example #24
0
static SeafRepo* create_repo (const char *repo_name)
{
    SeafRepo *repo;
    const char *repo_id;
    GError *error = NULL;
    char *wt_path;
    char cmd[1024];

    wt_path = g_build_filename (WORKTREE_DIR, repo_name, NULL);
    snprintf (cmd, 1024, "cp -R %s/data %s", TEST_DIR, wt_path);
    int ret = system (cmd);
    if (ret < 0 || WEXITSTATUS(ret) != 0) {
        fprintf (stderr, "Failed to copy data\n");
        exit (1);
    }

    /* create a non encrypted repo */
    repo_id = seafile_create_repo (repo_name, "test",
                "example@abc.com", NULL, &error);
    if (!repo_id) {
        fprintf (stderr, "Failed to create repo: %s.\n", error->message);
        exit (1);
    }
    repo = seaf_repo_manager_get_repo (seaf->repo_mgr, repo_id);
   
    g_free (wt_path);
    return repo;
}
Example #25
0
void template_getopt(int* argc, char** argv[])
{
    /*
     * The "getopt" function will be called from the parent to
     * process plugin options.
     */
    int c;
    while ((c = getopt(*argc, *argv, "?fx:")) != EOF) {
        switch (c) {
        case '?':
            template_usage();
            exit(1);
            break;
        case 'f':
            opt_f = 1;
            break;
        case 'x':
            opt_x = strdup(optarg);
            break;
        default:
            template_usage();
            exit(1);
        }
    }
}
Example #26
0
nitf_Record *readRecord(char *file)
{
    nitf_IOHandle in;            /* Handle for input */
    nitf_Reader *reader;         /* Reader object */
    nitf_Record *record;         /* The result */
    nitf_Error error;            /* For errors */

    in = nitf_IOHandle_create(file,
                              NITF_ACCESS_READONLY, NITF_OPEN_EXISTING, &error);
    if (NITF_INVALID_HANDLE(in))
    {
        nitf_Error_print(&error, stderr, "Error opening input ");
        exit(EXIT_FAILURE);
    }

    reader = nitf_Reader_construct(&error);
    if (!reader)
    {
        nitf_Error_print(&error, stderr, "Error creating reader ");
        exit(EXIT_FAILURE);
    }

    record = nitf_Reader_read(reader, in, &error);
    if (!record)
    {
        nitf_Error_print(&error, stderr, "Error reading input ");
        exit(EXIT_FAILURE);
    }

    nitf_IOHandle_close(in);
    nitf_Reader_destruct(&reader);
    return(record);
}
Example #27
0
void foo()
{
#pragma xmp template_fix [gblock(m)] t[NSIZE]
  int *a;
#pragma xmp align a[i] with t[i]
#pragma xmp shadow a[2]

  a = (int*)xmp_malloc(xmp_desc_of(a), NSIZE);

#pragma xmp loop on t[i]
  for (int i = 0; i < N; i++)
    a[i] = i;

#pragma xmp reflect (a) width (/periodic/1:1) async (100)
#pragma xmp wait_async (100)

#pragma xmp loop on t[i]
  for (int i = 0; i < N; i++){
    if(a[i-1] != (i-1+N)%N){
      printf("ERROR Lower in %d (%06d) (%06d)\n", (int)i, a[i-1], (int)(i-1+N)%N);
      exit(1);
    }
    if(a[i+1] != (i+1+N)%N){
      printf("ERROR Upper in %d (%06d) (%06d)\n", (int)i, a[i+1], (int)(i+1+N)%N);
      exit(1);
    }
  }

#pragma xmp task on p[0]
  {
    printf("PASS\n");
  }
}
Example #28
0
void sharedMemory()
{

    // make the key:
    if ((key = ftok("file", 'R')) == -1) {
        perror("ftok");
        exit(1);
    }

    // connect to (and possibly create) the segment:
    if ((shmid = shmget(key, sizeof(pthread_t), 0644 | IPC_CREAT)) == -1) {
        perror("shmget");
        exit(1);
    }

    // attach to the segment to get a pointer to it:
    cnt = shmat(shmid, (void *)0, 0);
    if (cnt == (int *)(-1)) {
        perror("shmat");
        exit(1);
    }

    // read or modify the segment, based on the command line:
	*cnt = 0;
    printf("segment contains: \"%d\"\n", *cnt);

}
Example #29
0
void
InsertString (stringlist_t * list, char *string)
{

  if (!list->list)
    {
      list->max_index = list->block_size;
      list->num_strings = 0;
      list->list = (char **) malloc (list->max_index * sizeof (char *));
      if (!list->list)
	{
	  LogError ("malloc() error in %s line %d: %s\n", __FILE__, __LINE__,
		    strerror (errno));
	  exit (250);
	}
    }
  list->list[list->num_strings++] = string ? strdup (string) : NULL;

  if (list->num_strings == list->max_index)
    {
      list->max_index += list->block_size;
      list->list =
	(char **) realloc (list->list, list->max_index * sizeof (char *));
      if (!list->list)
	{
	  LogError ("realloc() error in %s line %d: %s\n", __FILE__, __LINE__,
		    strerror (errno));
	  exit (250);
	}
    }

}				// End of InsertString
/* goodG2B uses the GoodSource with the BadSink */
void CWE400_Resource_Exhaustion__fgets_fwrite_65b_goodG2BSink(int count)
{
    {
        size_t i = 0;
        FILE *pFile = NULL;
        const char *filename = "output_bad.txt";
        pFile = fopen(filename, "w+");
        if (pFile == NULL)
        {
            exit(1);
        }
        /* POTENTIAL FLAW: For loop using count as the loop variant and no validation
         * This can cause a file to become very large */
        for (i = 0; i < (size_t)count; i++)
        {
            if (strlen(SENTENCE) != fwrite(SENTENCE, sizeof(char), strlen(SENTENCE), pFile))
            {
                exit(1);
            }
        }
        if (pFile)
        {
            fclose(pFile);
        }
    }
}