示例#1
0
/*  Creates pipes, 2 for each counted pipe char (count) */
pipe_list_t *create_pipes(int count) {
    pipe_list_t *pipes = malloc(sizeof(pipe_list_t));
    if(!alloc_check(pipes)) {
        return 0;
    }

    if(count > 0) {
        pipes->pipes = malloc(2 * count * sizeof(int *));
        if(!alloc_check(pipes->pipes)) {
            return 0;
        }

        for(int i = 0; i < count; i++ ) {
            (pipes->pipes)[i] = malloc(2 * sizeof(int *));
            if(!alloc_check(pipes->pipes[i])) {
                free(pipes->pipes);
                free(pipes);
                return 0;
            }
            if(pipe(pipes->pipes[i]) < 0) {
                perror("Couldn't create a pipe");
            }
        }
    }

    pipes->length = count;
    pipes->curr = 0;

    return pipes;
}
示例#2
0
void first_pass(char *file_in) {
    FILE *fp = fopen(file_in, "r");
    char info[512];
    while (!feof(fp)) {
        fscanf(fp, "%511[^\n]\n", info);
        if (!is_empty(info)) {
            program_counter += 4;
            if (is_label(info)) {
                printf("info: %s - PC: %i\n", info, program_counter - 4);
                program_counter -= 4;
                strtok(info, ":");
                char *copy = (char *) calloc(512, sizeof(char));
    		    alloc_check(copy, "first_pass");
                strcpy(copy, info);
                insert_addr_label(addr_label, copy, program_counter);
            }
        }
    }
    print_addr_label_list();
    memory_end = program_counter;
    ldr_const_array = (uint32_t *) calloc(memory_end, sizeof(uint32_t));    
    alloc_check(ldr_const_array, "first_pass");
    program_counter = 0;
    fclose(fp);
}
示例#3
0
文件: test_list.c 项目: EmisFR/burp
END_TEST

static void do_test_check_browsedir_windows_blank(enum protocol protocol)
{
	struct sbuf *mb;
	const char *browsedir;
	char *last_bd_match=NULL;

	fail_unless((mb=sbuf_alloc(protocol))!=NULL);

	browsedir="";
	run_check_browsedir(browsedir, mb, CMD_FILE, "A:/aaa",
		&last_bd_match, "A:", 1, 1);
	run_check_browsedir(browsedir, mb, CMD_DIRECTORY, "C:/aaa",
		&last_bd_match, "C:", 1, 1);
	run_check_browsedir(browsedir, mb, CMD_FILE, "C:/aaa/file",
		&last_bd_match, "C:", 0, 1);
	run_check_browsedir(browsedir, mb, CMD_FILE, "C:/aaa/filx",
		&last_bd_match, "C:", 0, 1);
	run_check_browsedir(browsedir, mb, CMD_FILE, "D:/adf",
		&last_bd_match, "D:", 1, 1);

	sbuf_free(&mb);
	free_w(&last_bd_match);
	alloc_check();
}
示例#4
0
文件: test_list.c 项目: EmisFR/burp
END_TEST

START_TEST(test_check_browsedir_alloc_error)
{
	char *path;
	size_t bdlen;
	struct sbuf *mb;
	const char *browsedir;
	char *last_bd_match=NULL;

	fail_unless((mb=sbuf_alloc(PROTO_1))!=NULL);

	browsedir="";
	bdlen=0;
	fail_unless((path=strdup_w("aaa", __func__))!=NULL);
	iobuf_from_str(&mb->path, CMD_FILE, path);
	alloc_errors=1;
	fail_unless(check_browsedir(
		browsedir,
		mb,
		bdlen,
		&last_bd_match)
			==-1);

	sbuf_free(&mb);
	free_w(&last_bd_match);
	alloc_check();
}
示例#5
0
static void tear_down(struct asfd **asfd)
{
    asfd_free(asfd);
    fail_unless(!fzp_close(&output));
    fail_unless(!recursive_delete(CLIENTCONFDIR));
    alloc_check();
}
示例#6
0
文件: test_cstat.c 项目: rubenk/burp
static void tear_down(struct cstat **cstat)
{
	sdirs_free((struct sdirs **)&(*cstat)->sdirs);
	cstat_free(cstat);
	alloc_check();
	clean();
}
示例#7
0
文件: test_list.c 项目: EmisFR/burp
END_TEST

static void do_test_check_browsedir_null_or_blank(enum protocol protocol,
	const char *browsedir)
{
	struct sbuf *mb;
	char *last_bd_match=NULL;

	fail_unless((mb=sbuf_alloc(protocol))!=NULL);

	run_check_browsedir(browsedir, mb, CMD_FILE, "aaa",
		&last_bd_match, "aaa",  1, 0);
	run_check_browsedir(browsedir, mb, CMD_DIRECTORY, "/",
		&last_bd_match, "/",    1, 1);
	run_check_browsedir(browsedir, mb, CMD_DIRECTORY, "/asdf",
		&last_bd_match, "/",    0, 1);
	run_check_browsedir(browsedir, mb, CMD_DIRECTORY, "/asdf/blah",
		&last_bd_match, "/",    0, 1);
	run_check_browsedir(browsedir, mb, CMD_FILE, "zzz",
		&last_bd_match, "zzz",  1, 0);
	run_check_browsedir(browsedir, mb, CMD_FILE, "zzzz//",
		&last_bd_match, "zzzz",  1, 1);

	sbuf_free(&mb);
	free_w(&last_bd_match);
	alloc_check();
}
示例#8
0
instr_t *data_proc_gen(data_proc_t *bin_instr) {
    bin_instr->cond = 0xe;
    instr_t *instr = (instr_t *) malloc(sizeof(instr_t));
    alloc_check(instr, "data_proc_gen");
    instr->data_proc = *bin_instr;
    free(bin_instr);
    return instr;
}
示例#9
0
文件: test_list.c 项目: EmisFR/burp
static void tear_down(struct asfd **asfd, struct sdirs **sdirs)
{
	asfd_free(asfd);
	asfd_mock_teardown(&reads, &writes);
	sdirs_free(sdirs);
	fail_unless(recursive_delete(BASE)==0);
	alloc_check();
}
示例#10
0
static void tear_down(struct fdirs **fdirs,
	struct sdirs **sdirs, struct conf ***confs)
{
	fdirs_free(fdirs);
	sdirs_free(sdirs);
	confs_free(confs);
	alloc_check();
}
示例#11
0
static void tear_down(
	struct sdirs **sdirs, struct fdirs **fdirs, struct conf ***confs)
{
	sdirs_free(sdirs);
	fdirs_free(fdirs);
	confs_free(confs);
	fail_unless(!recursive_delete(BASE));
	alloc_check();
}
示例#12
0
static void tear_down(struct asfd **asfd, struct conf ***confs)
{
	asfd_free(asfd);
	confs_free(confs);
	asfd_mock_teardown(&reads, &writes);
//printf("%d %d\n", alloc_count, free_count);
	alloc_check();
	fail_unless(recursive_delete(BASE)==0);
}
示例#13
0
文件: test_find.c 项目: vanElden/burp
static void tear_down(FF_PKT **ff, struct conf ***confs)
{
	fail_unless(e==NULL);
	find_files_free(ff);
	confs_free(confs);
	strlists_free(&expected);
	fail_unless(recursive_delete(BASE)==0);
	alloc_check();
}
示例#14
0
文件: test_cstat.c 项目: rubenk/burp
static void test_cstat_remove_teardown(struct conf ***globalcs,
	struct cstat **clist)
{
	confs_free(globalcs);
	cstat_list_free_sdirs(*clist);
	cstat_list_free(clist);
	clean();
	alloc_check();
}
示例#15
0
EXT wigner* wigner_new
  (grid* g)
{

  int i,
      Nx = g-> x-> n_val,
      Ny = g-> y-> n_val;

  wigner* w = quix_object_alloc(wigner);

  w-> gd  = grid_copy(g);
  w-> val = quix_alloc(double*,Nx);
  alloc_check(w-> val,"wigner_new");

  loop(i,Nx) {
    w-> val[i]  = double_alloc(Ny);
    alloc_check(w-> val[i],"wigner_new");
  }
示例#16
0
int main(int argc, char *argv[])
{
	void *mem;

	plan_tests(7);

	mem = malloc(1179648);
	alloc_init(mem, 1179648);
	ok1(alloc_check(mem, 1179648));
	ok1(alloc_get(mem, 1179648, 48, 16));
	ok1(alloc_check(mem, 1179648));
	ok1(alloc_get(mem, 1179648, 53, 16));
	ok1(alloc_check(mem, 1179648));
	ok1(alloc_get(mem, 1179648, 53, 16));
	ok1(alloc_check(mem, 1179648));
	free(mem);

	return exit_status();
}
示例#17
0
static void tear_down(struct async **as,
	struct sdirs **sdirs, struct conf ***confs)
{
	async_free(as);
	sdirs_free(sdirs);
	confs_free(confs);
	fail_unless(!recursive_delete(BASE));
//printf("%d %d\n", alloc_count, free_count);
	alloc_check();
}
示例#18
0
void*       
quix_object_alloc_function          
(int size)
{

  void* pointer = malloc( size );
  alloc_check(pointer, "quix_object_alloc");
  allocator((int)pointer);
  return pointer;

}
示例#19
0
static void tear_down(struct async **as, struct asfd **asfd,
	struct sdirs **sdirs, struct conf ***confs)
{
	async_free(as);
	asfd_free(asfd);
	sdirs_free(sdirs);
	asfd_mock_teardown(&reads, &writes);
	confs_free(confs);
//printf("%d %d\n", alloc_count, free_count);
	alloc_check();
}
示例#20
0
static void tear_down(struct sbuf **sb, struct cntr **cntr,
	struct conf ***confs, struct asfd **asfd)
{
	clean();
	sbuf_free(sb);
	cntr_free(cntr);
	confs_free(confs);
	asfd_free(asfd);
	asfd_mock_teardown(&areads, &awrites);
	alloc_check();
}
示例#21
0
文件: test_cstat.c 项目: rubenk/burp
END_TEST

START_TEST(test_cstat_get_client_names)
{
	struct cstat *clist=NULL;
	const char *cnames[] =
		{"cli1", "cli2", "cli3", NULL};
	const char *cnames_add[] =
		{"cli0", "cli1", "cli2", "cli2a", "cli3", "cli4", NULL};
	const char *cnames_rm[] =
		{"cli2", NULL};
	const char *tmp_files[] =
		{".abc", "xyz~", NULL };

	clean();
	build_clientconfdir_files(cnames);
	fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
	assert_cstat_list(clist, cnames);

	// Call again with the same clientconfdir files.
	clean();
	build_clientconfdir_files(cnames);
	fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
	assert_cstat_list(clist, cnames);

	// Call again with extra clientconfdir files.
	clean();
	build_clientconfdir_files(cnames_add);
	fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
	assert_cstat_list(clist, cnames_add);

	// Call again with fewer clientconfdir files.
	// The list will not be shorter.
	clean();
	build_clientconfdir_files(cnames_rm);
	fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
	assert_cstat_list(clist, cnames_add);

	// Temporary files should be missed.
	clean();
	build_clientconfdir_files(tmp_files);
	fail_unless(!cstat_get_client_names(&clist, CLIENTCONFDIR));
	assert_cstat_list(clist, cnames_add);

	// Cause an error.
	clean();
	fail_unless(cstat_get_client_names(&clist, CLIENTCONFDIR)==-1);

	cstat_list_free(&clist);
	clean();
	alloc_check();
}
示例#22
0
static void do_snapshot_test(
	const char *orig_client,
	int expected_ret,
	void setup_callback(
		struct asfd *csin,
		struct asfd *csout,
		struct asfd *so_asfd
	)
)
{
	struct asfd *csin;
	struct asfd *csout;
	struct asfd *so_asfd;
	struct async *as;
	struct sel *sel;

	as=setup_async();
	csin=asfd_mock_setup(&reads_csin, &writes_csin);
	csout=asfd_mock_setup(&reads_csout, &writes_csout);
	so_asfd=asfd_mock_setup(&reads_so, &writes_so);
        fail_unless((csin->desc=strdup_w("csin", __func__))!=NULL);
        fail_unless((csout->desc=strdup_w("csout", __func__))!=NULL);
        fail_unless((so_asfd->desc=strdup_w("so_asfd", __func__))!=NULL);
	as->asfd_add(as, csin);
	as->asfd_add(as, csout);
	as->asfd_add(as, so_asfd);
	as->read_write=async_rw_simple;
	as->write=async_write_simple;
	setup_callback(csin, csout, so_asfd);

	fail_unless((sel=sel_alloc())!=NULL);

	fail_unless(!status_client_ncurses_init(ACTION_STATUS_SNAPSHOT));
	fail_unless(status_client_ncurses_main_loop(
		as,
		so_asfd,
		sel,
		orig_client
	)==expected_ret);

	sel_free(&sel);
	asfd_free(&csin);
	asfd_free(&csout);
	asfd_free(&so_asfd);
	asfd_mock_teardown(&reads_csin, &writes_csin);
	asfd_mock_teardown(&reads_csout, &writes_csout);
	asfd_mock_teardown(&reads_so, &writes_so);
	async_free(&as);

	alloc_check();
}
示例#23
0
void init_data_aloc_table(data_aloc_table_t *table)
{
    /* PRE:  There is sufficient space pointed to by table. */
    /* POST: Initialises the data_aloc_table_t pointed to by table. exit() if
             unsuccessful. */

    assert (table != NULL);

    table->header = malloc(sizeof(data_aloc_table_elem_t));
    alloc_check(table->header, 'm');

    table->header->next = NULL;
    table->last = NULL;
}
示例#24
0
static data_aloc_table_elem_t *create_data_aloc_table_elem(uint32_t addr, 
                                                           uint32_t data)
{
    /* PRE:  True */
    /* POST: Creates and returns a new heap-allocated data_aloc_table_elem_t
             holding the given address and data. */

    data_aloc_table_elem_t *new_elem = malloc(sizeof(data_aloc_table_elem_t));
    alloc_check(new_elem, 'm');

    new_elem->addr = addr;
    new_elem->data = data;
    new_elem->next = NULL;

    return new_elem;
}
static char *cut_string(char *str, int from, int to)
{
    /* PRE:  Takes a pointer to a string and two indexes.
     * POST: Teturns a cut string that starts at char str[from] and finishes 
             at str[to]. To is after from, and both are contained in the 
             string. */

    assert (str != NULL && to >= from);
    int str_len = strlen(str);
    assert (from >= 0 && from <= str_len && to >= 0 && to <= str_len);
 
    char *str_cut = malloc(sizeof(char) * (to - from + 1));
    alloc_check(str_cut, 'm');
    strncpy(str_cut, str + from, to - from);
    str_cut[to - from] = '\0';
    return str_cut;
}
示例#26
0
文件: test_cstat.c 项目: rubenk/burp
END_TEST

static void do_test_cstat_reload_from_client_confs(enum protocol protocol)
{
	struct cstat *c1;
	struct cstat *c2;
	struct cstat *clist=NULL;
	c1=setup_cstat("cli1", protocol);
	c2=setup_cstat("cli2", protocol);
	cstat_add_to_list(&clist, c1);
	cstat_add_to_list(&clist, c2);
	c1->permitted=1;

	// First time, nothing is reloaded.
	fail_unless(reload_from_clientdir(&clist)==0);
	fail_unless(c1->run_status==RUN_STATUS_IDLE);
	fail_unless(c2->run_status==RUN_STATUS_UNSET);
	fail_unless(c1->bu==NULL);
	fail_unless(c2->bu==NULL);

	// Add some storage dirs, and c1 is loaded.
	build_storage_dirs((struct sdirs *)c1->sdirs,
		sd123, ARR_LEN(sd123));
	fail_unless(reload_from_clientdir(&clist)==1);
	fail_unless(c1->run_status==RUN_STATUS_IDLE);
	fail_unless(c2->run_status==RUN_STATUS_UNSET);
	fail_unless(c1->bu!=NULL);
	fail_unless(c2->bu==NULL);

	// Go again, nothing should be reloaded.
	fail_unless(reload_from_clientdir(&clist)==0);

	// Get a lock.
	lock_get_quick(((struct sdirs *)c1->sdirs)->lock);
	fail_unless(reload_from_clientdir(&clist)==1);

	sdirs_free((struct sdirs **)&c1->sdirs);
	sdirs_free((struct sdirs **)&c2->sdirs);
	cstat_list_free(&clist);
	clean();
	alloc_check();
}
示例#27
0
文件: test_list.c 项目: EmisFR/burp
static void do_test_check_browsedir(enum protocol protocol)
{
	struct sbuf *mb;
	const char *browsedir;
	char *last_bd_match=NULL;

	fail_unless((mb=sbuf_alloc(protocol))!=NULL);

	browsedir="/path";
	run_check_browsedir(browsedir, mb, CMD_FILE, "/aaaa/path/file",
		&last_bd_match, NULL, 0, 0);
	run_check_browsedir(browsedir, mb, CMD_FILE, "/pat/aaa/file",
		&last_bd_match, NULL, 0, 0);
	run_check_browsedir(browsedir, mb, CMD_DIRECTORY, "/path",
		&last_bd_match, ".",  1, 1);
	run_check_browsedir(browsedir, mb, CMD_DIRECTORY, "/path/",
		&last_bd_match, ".",  0, 1);
	run_check_browsedir(browsedir, mb, CMD_FILE, "/path/aa/file",
		&last_bd_match, "aa", 1, 1);
	// Get a bit more coverage by setting the statp mode to S_IFDIR.
	mb->statp.st_mode &= ~(S_IFMT);
	mb->statp.st_mode |= S_IFDIR;
	run_check_browsedir(browsedir, mb, CMD_FILE, "/path/to/file",
		&last_bd_match, "to", 1, 1);
	run_check_browsedir(browsedir, mb, CMD_FILE, "/path/to/gggg",
		&last_bd_match, "to", 0, 1);
	run_check_browsedir(browsedir, mb, CMD_FILE, "/path/to/gggg/zzz",
		&last_bd_match, "to", 0, 1);
	run_check_browsedir(browsedir, mb, CMD_FILE, "/path/to/hhhh",
		&last_bd_match, "to", 0, 1);
	run_check_browsedir(browsedir, mb, CMD_FILE, "/path/so/hhhh",
		&last_bd_match, "so", 1, 1);
	run_check_browsedir(browsedir, mb, CMD_FILE, "/patha/aaa/file",
		&last_bd_match, "so", 0, 0);
	run_check_browsedir(browsedir, mb, CMD_FILE, "path/aaa/file",
		&last_bd_match, "so", 0, 0);

	sbuf_free(&mb);
	free_w(&last_bd_match);
	alloc_check();
}
示例#28
0
static void do_simple_test(
	const char *orig_client,
	int expected_ret,
	void setup_callback(struct asfd *asfd),
	void setup_stdout_callback(struct asfd *asfd)
)
{
	struct asfd *asfd;
	struct asfd *so_asfd;
	struct async *as;

	as=setup_async();
	asfd=asfd_mock_setup(&reads, &writes);
	so_asfd=asfd_mock_setup(&reads_so, &writes_so);
	as->asfd_add(as, asfd);
	as->asfd_add(as, so_asfd);
	asfd->as=as;
	as->read_write=async_rw_simple;
	as->write=async_write_simple;
	setup_callback(asfd);
	if(setup_stdout_callback)
		setup_stdout_callback(so_asfd);

	fail_unless(!status_client_ncurses_init(ACTION_STATUS_SNAPSHOT));
	fail_unless(status_client_ncurses_main_loop(
		as,
		so_asfd,
		orig_client
	)==expected_ret);
	asfd_free(&asfd);
	asfd_free(&so_asfd);
	asfd_mock_teardown(&reads, &writes);
	asfd_mock_teardown(&reads_so, &writes_so);
	async_free(&as);

	alloc_check();
}
示例#29
0
文件: test_list.c 项目: EmisFR/burp
END_TEST

static void do_test_check_browsedir_root(enum protocol protocol)
{
	struct sbuf *mb;
	const char *browsedir;
	char *last_bd_match=NULL;

	fail_unless((mb=sbuf_alloc(protocol))!=NULL);

	browsedir="/";
	run_check_browsedir(browsedir, mb, CMD_FILE, "aaa",
		&last_bd_match, NULL,  0, 0);
	run_check_browsedir(browsedir, mb, CMD_DIRECTORY, "/",
		&last_bd_match, ".",   1, 1);
	run_check_browsedir(browsedir, mb, CMD_DIRECTORY, "/aa",
		&last_bd_match, "aa",  1, 1);
	run_check_browsedir(browsedir, mb, CMD_FILE, "/aa/bb",
		&last_bd_match, "aa",  0, 1);

	sbuf_free(&mb);
	free_w(&last_bd_match);
	alloc_check();
}
示例#30
0
文件: test_dpth.c 项目: EmisFR/burp
static void tear_down(struct dpth **dpth)
{
	dpth_free(dpth);
	fail_unless(recursive_delete(lockpath)==0);
	alloc_check();
}