예제 #1
0
    virtual void onDraw(SkCanvas* canvas) {

        PFCreateOpt gOpts[] = {
            create_save_layer_opt_1_v1,
            create_save_layer_opt_1_v2,
            create_save_layer_opt_1_v3,
            create_save_layer_opt_1_v4,
            create_save_layer_opt_2_v1,
            create_save_layer_opt_2_v2,
            create_save_layer_opt_2_v3,
            create_save_layer_opt_2_v4,
        };

        SkTDArray<DrawType> prePattern, postPattern;
        int xPos = 0, yPos = 0;

        for (size_t i = 0; i < SK_ARRAY_COUNT(gOpts); ++i) {
            SkAutoTUnref<SkPicture> pre((*gOpts[i])(&prePattern, &postPattern, fCheckerboard));

            if (!(check_pattern(*pre, prePattern))) {
                WARN("Pre optimization pattern mismatch");
                SkASSERT(0);
            }

            canvas->save();
                canvas->translate(SkIntToScalar(xPos), SkIntToScalar(yPos));
                pre->draw(canvas);
                xPos += pre->width();
            canvas->restore();

            // re-render the 'pre' picture and thus 'apply' the optimization
            SkAutoTUnref<SkPicture> post(new SkPicture);

            SkCanvas* recordCanvas = post->beginRecording(pre->width(), pre->height());

            pre->draw(recordCanvas);

            post->endRecording();

            if (!(check_pattern(*post, postPattern))) {
                WARN("Post optimization pattern mismatch");
                SkASSERT(0);
            }

            canvas->save();
                canvas->translate(SkIntToScalar(xPos), SkIntToScalar(yPos));
                post->draw(canvas);
                xPos += post->width();
            canvas->restore();

            if (xPos >= kWidth) {
                // start a new line
                xPos = 0;
                yPos += post->height();
            }

            // TODO: we could also render the pre and post pictures to bitmaps
            // and manually compare them in this method
        }
    }
예제 #2
0
void process_multipart(http_req *req)
{
	char *startp, *strp;
	char *boundary;
	char *varname;
	int remain_len;
	
	
	boundary = strstr(req->content_type, "boundary=");
	boundary += 9;
    
	startp = req->content->buf;
	remain_len = req->content->len;
	
	while(remain_len > 0) 
	{
		if((startp = check_pattern(startp, remain_len, boundary)) == NULL )
			break;
	
		if(startp-4 > req->content->buf)
			*(startp-4) = '\0'; /* \r\n-- */
		
		startp += strlen(boundary);
		
		if(*startp=='-' && *(startp+1)=='-')
			break;  /* end */ /* Roger: This check method is right?? */
		
		startp +=2;
		
		remain_len = req->content->len - (startp - req->content->buf);
		if (!strncasecmp(startp, "Content-Disposition:", 20) ) 
		{
			if((varname = check_pattern(startp, remain_len, "name=\"")) != NULL ) 
			{
					
				/* find out begin of file */
		    	if((strp = check_pattern(startp, remain_len, "\r\n\r\n")) != NULL) 
		    	{
		    		startp = strp+4;
		    	}
		    	else if((strp = check_pattern(startp, remain_len, "\n\n")) != NULL) 
		    	{
		    		startp = strp+2;
		    	}
		    	else 
		    	{
		    		diag_printf("Can not find value of %s\n", varname);
		    		return;
		    	}
		    	varname += 6;
		    	strp = strchr( varname, '"');	
		    	*strp =  '\0';//comment by haitao:replace '"' with '\0',to add end char for name.
		    	query_set(req, varname, startp);	
		    }
		}
		remain_len =  req->content->len -(startp - req->content->buf);
	}
}
예제 #3
0
int mtd_torture(const struct mtd_dev_info *mtd, int fd, int eb)
{
	int err, i, patt_count;
	void *buf;

	normsg("run torture test for PEB %d", eb);
	patt_count = ARRAY_SIZE(patterns);

	buf = malloc(mtd->eb_size);
	if (!buf) {
		errmsg("cannot allocate %d bytes of memory", mtd->eb_size);
		return -1;
	}

	for (i = 0; i < patt_count; i++) {
		err = mtd_erase(mtd, fd, eb);
		if (err)
			goto out;

		/* Make sure the PEB contains only 0xFF bytes */
		err = mtd_read(mtd, fd, eb, 0, buf, mtd->eb_size);
		if (err)
			goto out;

		err = check_pattern(buf, 0xFF, mtd->eb_size);
		if (err == 0) {
			errmsg("erased PEB %d, but a non-0xFF byte found", eb);
			errno = EIO;
			goto out;
		}

		/* Write a pattern and check it */
		memset(buf, patterns[i], mtd->eb_size);
		err = mtd_write(mtd, fd, eb, 0, buf, mtd->eb_size);
		if (err)
			goto out;

		memset(buf, ~patterns[i], mtd->eb_size);
		err = mtd_read(mtd, fd, eb, 0, buf, mtd->eb_size);
		if (err)
			goto out;

		err = check_pattern(buf, patterns[i], mtd->eb_size);
		if (err == 0) {
			errmsg("pattern %x checking failed for PEB %d",
				patterns[i], eb);
			errno = EIO;
			goto out;
		}
	}

	err = 0;
	normsg("PEB %d passed torture test, do not mark it a bad", eb);

out:
	free(buf);
	return -1;
}
예제 #4
0
int check_kallsyms_header(unsigned long *addr) {
    if (check_pattern(addr, pattern_kallsyms_addresses, sizeof(pattern_kallsyms_addresses) / 4) == 0) {
        return 0;
    } else if (check_pattern(addr, pattern_kallsyms_addresses2, sizeof(pattern_kallsyms_addresses2) / 4) == 0) {
        return 0;
    } else if (check_pattern(addr, pattern_kallsyms_addresses3, sizeof(pattern_kallsyms_addresses3) / 4) == 0) {
        return 0;
    }

    return -1;
}
예제 #5
0
debug_guard::~debug_guard()
{
   check_patterns(file, line);
   if(check_pattern(g1) || check_pattern(g2))
   {
      cerr << "Error: memory corruption " << file << "@" << line << endl;
   }
   patterns->erase(this);
   if(--pattern_count == 0)
   {
      delete patterns;
      patterns = 0;
   }
}
예제 #6
0
/**
 * ubi_dbg_check_all_ff - check that a region of flash is empty.
 * @ubi: UBI device description object
 * @pnum: the physical eraseblock number to check
 * @offset: the starting offset within the physical eraseblock to check
 * @len: the length of the region to check
 *
 * This function returns zero if only 0xFF bytes are present at offset
 * @offset of the physical eraseblock @pnum, and a negative error code if not
 * or if an error occurred.
 */
int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
{
	size_t read;
	int err;
	loff_t addr = (loff_t)pnum * ubi->peb_size + offset;

	mutex_lock(&ubi->dbg_buf_mutex);
	err = ubi->mtd->read(ubi->mtd, addr, len, &read, ubi->dbg_peb_buf);
	if (err && err != -EUCLEAN) {
		ubi_err("error %d while reading %d bytes from PEB %d:%d, "
			"read %zd bytes", err, len, pnum, offset, read);
		goto error;
	}

	err = check_pattern(ubi->dbg_peb_buf, 0xFF, len);
	if (err == 0) {
		ubi_err("flash region at PEB %d:%d, length %d does not "
			"contain all 0xFF bytes", pnum, offset, len);
		goto fail;
	}
	mutex_unlock(&ubi->dbg_buf_mutex);

	return 0;

fail:
	ubi_err("paranoid check failed for PEB %d", pnum);
	ubi_msg("hex dump of the %d-%d region", offset, offset + len);
	print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
		       ubi->dbg_peb_buf, len, 1);
	err = -EINVAL;
error:
	ubi_dbg_dump_stack();
	mutex_unlock(&ubi->dbg_buf_mutex);
	return err;
}
예제 #7
0
파일: parser.c 프로젝트: ianliu/tosco
/*carrega as estacoes de um pattern em um vetor*/
int load_pattern(FILE *file,int id,int station,int **stations){
	int i,j,count=0;
	int dif;
	int plus;
	int st=0;
	int data[53];

	if(check_pattern(file,id,data)){
		*stations=malloc(data[0]*sizeof(int));
		for(i=0;data[i]!=-1;i++)
			count++;

		for(i=2;i<count;i+=4){
			if (i+2 < count){
				dif=data[i+2]-data[i];
				plus=data[i+1]-data[i];
				for(j=1;j<=dif+1;j++,st++)
					(*stations)[st]=st-data[1]+station+plus+1;
			}
			else {
				plus=data[i+1]-data[i];
				(*stations)[st]=st-data[1]+station+plus+1;
			}
		}
		return TRUE;
	}
	else
		return FALSE;
}
예제 #8
0
s32 sys_event_flag_trywait(u32 id, u64 bitptn, u32 mode, vm::ptr<u64> result)
{
	sys_event_flag.Log("sys_event_flag_trywait(id=0x%x, bitptn=0x%llx, mode=0x%x, result=*0x%x)", id, bitptn, mode, result);

	LV2_LOCK;

	if (result) *result = 0; // This is very annoying.

	if (!lv2_event_flag_t::check_mode(mode))
	{
		sys_event_flag.Error("sys_event_flag_trywait(): unknown mode (0x%x)", mode);
		return CELL_EINVAL;
	}

	const auto eflag = idm::get<lv2_event_flag_t>(id);

	if (!eflag)
	{
		return CELL_ESRCH;
	}

	if (eflag->check_pattern(bitptn, mode))
	{
		const u64 pattern = eflag->clear_pattern(bitptn, mode);

		if (result) *result = pattern;

		return CELL_OK;
	}

	return CELL_EBUSY;
}
예제 #9
0
void lv2_event_flag_t::notify_all(lv2_lock_t& lv2_lock)
{
	CHECK_LV2_LOCK(lv2_lock);

	auto pred = [this](sleep_queue_t::value_type& thread) -> bool
	{
		auto& ppu = static_cast<PPUThread&>(*thread);

		// load pattern and mode from registers
		const u64 bitptn = ppu.GPR[4];
		const u32 mode = static_cast<u32>(ppu.GPR[5]);

		// check specific pattern
		if (check_pattern(bitptn, mode))
		{
			// save pattern
			ppu.GPR[4] = clear_pattern(bitptn, mode);

			if (!ppu.signal())
			{
				throw EXCEPTION("Thread already signaled");
			}

			return true;
		}

		return false;
	};

	// check all waiters; protocol is ignored in current implementation
	sq.erase(std::remove_if(sq.begin(), sq.end(), pred), sq.end());
}
예제 #10
0
void check_patterns(const char* f, int l)
{
   if(pattern_count)
   {
      std::set<debug_guard*, std::less<debug_guard*> >::iterator i, j;
      i = patterns->begin();
      j = patterns->end();
      while(i != j)
      {
         if(check_pattern((void*)(*i)->g1) || check_pattern((*i)->g2) || check_pattern((void*)(*i)->pc) || check_pattern((*i)->pnc))
         {
            cerr << "Error: static memory corruption at " << hex << *i << dec << " in " << (*i)->file << "@" << (*i)->line << " called from " << f << "@" << l << endl;
         }
         ++i;
      }
   }
}
예제 #11
0
파일: vzlist.c 프로젝트: kolyshkin/vzctl
static void filter_by_description()
{
	int i;

	for (i = 0; i < n_veinfo; i++) {
		if (!check_pattern(veinfo[i].description, desc_pattern))
			veinfo[i].hide = 1;
	}
}
예제 #12
0
파일: vzlist.c 프로젝트: kolyshkin/vzctl
static void filter_by_name()
{
	int i;

	for (i = 0; i < n_veinfo; i++) {
		if (!check_pattern(veinfo[i].name, name_pattern))
			veinfo[i].hide = 1;
	}
}
예제 #13
0
bool is_infected(FILE *fp)
{
    char Bootloader[] = \
    "\xfa\x66\x31\xc0\x8e\xd0\x8e\xc0\x8e\xd8\xbc\x00\x7c\xfb\x88\x16"
    "\x93\x7c\x66\xb8\x20\x00\x00\x00\x66\xbb\x22\x00\x00\x00\xb9\x00"
    "\x80\xe8\x14\x00\x66\x48\x66\x83\xf8\x00\x75\xf5\x66\xa1\x00\x80"
    "\xea\x00\x80\x00\x00";

    const size_t bootloader_offset = 0;
    bool has_bootloader = check_pattern(fp, bootloader_offset, Bootloader, sizeof(Bootloader));
    if (has_bootloader) printf("[+] Petya bootloader detected!\n");

    char http_pattern[] = "http://";
    const size_t http_offset = 54 * SECTOR + 0x29;
    bool has_http = check_pattern(fp, http_offset, http_pattern, sizeof(http_pattern));
    if (has_http) printf("[+] Petya http address detected!\n");

    return has_bootloader || has_http;
}
예제 #14
0
int WEB_check_upload_image_last(http_req *req, char *buf, int len)
{
	char *boundary, *endp;
	int actualLen;
		
	boundary = strstr(req->content_type, "boundary=");
	boundary += 9;
	
	if( (endp = check_pattern( buf, len, boundary)) != NULL) 
	{
		endp -= 4; /* \r\n-- */
		actualLen = endp - buf;	
	}
	else
	{
		actualLen=len;
	}
	return actualLen;
}
예제 #15
0
int				check_tetriminos(t_list *data)
{
	char	*s;
	size_t	i;

	i = 0;
	if (!data)
		return (0);
	while (data)
	{
		s = data->content;
		if (check_chars(s, 0) == 0 || check_pattern(s, 0, 0, 0) == 0)
			return (0);
		if (i > 26)
			return (0);
		data = data->next;
		i++;
	}
	return (1);
}
예제 #16
0
// _ReadIndexEntry
bool
ResourceFile::_ReadIndexEntry(int32 index, uint32 tableOffset, bool peekAhead)
{
	bool result = true;
	resource_index_entry entry;
	// read one entry
	off_t entryOffset = tableOffset + index * kResourceIndexEntrySize;
	read_exactly(fFile, entryOffset, &entry, kResourceIndexEntrySize,
				 "Failed to read a resource index entry.");
	// check, if the end is reached early
	if (result && check_pattern(entryOffset, &entry,
								kResourceIndexEntrySize / 4, fHostEndianess)) {
		if (!peekAhead) {
			Warnings::AddCurrentWarning("Unexpected end of resource index "
										"table at index: %ld (/%ld).",
										index + 1, fResourceCount);
		}
		result = false;
	}
	uint32 offset = _GetUInt32(entry.rie_offset);
	uint32 size = _GetUInt32(entry.rie_size);
	// check the location
	if (result && offset + size > fFileSize) {
		if (peekAhead) {
			Warnings::AddCurrentWarning("Invalid data after resource index "
										"table.");
		} else {
			throw Exception("Invalid resource index entry: index: %ld, "
							"offset: %lu (%lx), size: %lu (%lx).", index + 1,
							offset, offset, size, size);
		}
		result = false;
	}
	// add the entry
	if (result) {
		ResourceItem* item = new ResourceItem;
		item->SetLocation(offset, size);
		AddItem(item, index);
	}
	return result;
}
예제 #17
0
char *WEB_upload_file(http_req *req, char *filename, int *len)
{
	char *file, *boundary, *endp;
	int rlen;
	
	file = query_getvar( req, filename);
	
	if( !file)
		return NULL;
		
	boundary = strstr(req->content_type, "boundary=");
	boundary += 9;
	
	rlen = req->content->len - (file - req->content->buf);
	if( (endp = check_pattern( file, rlen, boundary)) != NULL) {
		endp -= 4; /* \r\n-- */
		*len = endp - file;
	
		return file;
	}
	else
		return NULL;
}
예제 #18
0
파일: vo_opengl.c 프로젝트: DZW314/mpv
static void flip_page(struct vo *vo)
{
    struct gl_priv *p = vo->priv;
    GL *gl = p->gl;

    mpgl_swap_buffers(p->glctx);

    p->frames_rendered++;
    if (p->frames_rendered > 5 && !p->use_gl_debug)
        gl_video_set_debug(p->renderer, false);

    if (p->use_glFinish)
        gl->Finish();

    if (p->waitvsync || p->opt_pattern[0]) {
        if (gl->GetVideoSync) {
            unsigned int n1 = 0, n2 = 0;
            gl->GetVideoSync(&n1);
            if (p->waitvsync)
                gl->WaitVideoSync(2, (n1 + 1) % 2, &n2);
            int step = n1 - p->prev_sgi_sync_count;
            p->prev_sgi_sync_count = n1;
            MP_DBG(vo, "Flip counts: %u->%u, step=%d\n", n1, n2, step);
            if (p->opt_pattern[0])
                check_pattern(vo, step);
        } else {
            MP_WARN(vo, "GLX_SGI_video_sync not available, disabling.\n");
            p->waitvsync = 0;
            p->opt_pattern[0] = 0;
        }
    }
    while (p->opt_vsync_fences > 0 && p->num_vsync_fences >= p->opt_vsync_fences) {
        gl->ClientWaitSync(p->vsync_fences[0], GL_SYNC_FLUSH_COMMANDS_BIT, 1e9);
        gl->DeleteSync(p->vsync_fences[0]);
        MP_TARRAY_REMOVE_AT(p->vsync_fences, p->num_vsync_fences, 0);
    }
}
예제 #19
0
char *WEB_check_upload_image_first(http_req *req, char *filename, int *len)
{
	char *file, *boundary, *endp;
	int rlen;
	
	file = query_getvar( req, filename);
	
	if( !file)
		return NULL;
		
	boundary = strstr(req->content_type, "boundary=");
	boundary += 9;
	//here,still parse and copy the HTTP post body in request buf.
	rlen = req->content->len - (file - &(req->request[req->request_idx]));
	if( (endp = check_pattern( file, rlen, boundary)) != NULL) {
		endp -= 4; /* \r\n-- */
		*len = endp - file;
	}
	else
	{
		*len=rlen;
	}
	return file;
}
예제 #20
0
s32 sys_event_flag_wait(PPUThread& ppu, u32 id, u64 bitptn, u32 mode, vm::ptr<u64> result, u64 timeout)
{
	sys_event_flag.Log("sys_event_flag_wait(id=0x%x, bitptn=0x%llx, mode=0x%x, result=*0x%x, timeout=0x%llx)", id, bitptn, mode, result, timeout);

	const u64 start_time = get_system_time();

	// If this syscall is called through the SC instruction, these registers must already contain corresponding values.
	// But let's fixup them (in the case of explicit function call or something) because these values are used externally.
	ppu.GPR[4] = bitptn;
	ppu.GPR[5] = mode;

	LV2_LOCK;

	if (result) *result = 0; // This is very annoying.

	if (!lv2_event_flag_t::check_mode(mode))
	{
		sys_event_flag.Error("sys_event_flag_wait(): unknown mode (0x%x)", mode);
		return CELL_EINVAL;
	}

	const auto eflag = idm::get<lv2_event_flag_t>(id);

	if (!eflag)
	{
		return CELL_ESRCH;
	}

	if (eflag->type == SYS_SYNC_WAITER_SINGLE && eflag->sq.size() > 0)
	{
		return CELL_EPERM;
	}

	if (eflag->check_pattern(bitptn, mode))
	{
		const u64 pattern = eflag->clear_pattern(bitptn, mode);

		if (result) *result = pattern;

		return CELL_OK;
	}

	// add waiter; protocol is ignored in current implementation
	sleep_queue_entry_t waiter(ppu, eflag->sq);

	while (!ppu.unsignal())
	{
		CHECK_EMU_STATUS;

		if (timeout)
		{
			const u64 passed = get_system_time() - start_time;

			if (passed >= timeout)
			{
				if (result) *result = eflag->pattern;

				return CELL_ETIMEDOUT;
			}

			ppu.cv.wait_for(lv2_lock, std::chrono::microseconds(timeout - passed));
		}
		else
		{
			ppu.cv.wait(lv2_lock);
		}
	}
	
	// load pattern saved upon signaling
	if (result)
	{
		*result = ppu.GPR[4];
	}

	// check cause
	if (ppu.GPR[5] == 0)
	{
		return CELL_ECANCELED;
	}

	return CELL_OK;
}
예제 #21
0
int main(int argc, char *argv[])
{
	struct sock_info_t sock;
	int ret;
	int i;
	int len;
	unsigned char *tx_buf;
	unsigned char *rx_buf;
	unsigned char pattern;

	if (argc == 2) {
		len = atoi(argv[1]);
	} else {
		len = TEST_LEN;
	}

	tx_buf = (unsigned char *)malloc(sizeof(unsigned char)*len);
	if (tx_buf == NULL) {
		debug_print("malloc failed!\n");
		return 1;        
	}

	rx_buf = (unsigned char *)malloc(sizeof(unsigned char)*len);
	if (rx_buf == NULL) {
		free(tx_buf);
		debug_print("malloc failed!\n");
		return 1;        
	}

	ret = socket_open(&sock, TYPE_TCP);
	if (ret != LIBCOMMBUS_SUCCESS) {
		debug_print("open failed!\n");
		getchar();
		return 1;
	}

	ret = socket_connect(&sock, TEST_HOST, TEST_PORT);
        if (ret != LIBCOMMBUS_SUCCESS) {
                debug_print("connect failed!\n");
                getchar();
                return 1;
        }
	printf("--Ready to Run Test--\n");

	pattern = 0;
	while (1) {
		memset(tx_buf, pattern, len);

		ret = socket_write(&sock, tx_buf, len);
		if (ret != len) {
			debug_print("socket_write: len=%d error!\n", ret);
		}

		ret = socket_read(&sock, rx_buf, len);
		if (ret != len) {
			debug_print("socket_read: len=%d error!\n", ret);
		}

		if (check_pattern(rx_buf, pattern, len) == 0) {
			pattern++;
		} else {
			for (i = 0; i < len; i++) {
				printf("(%d)TX: %x, RX: %x\n", i, tx_buf[i], rx_buf[i]);
			}

			while (1);
		}
		debug_print("RX:%x\n", rx_buf[0]);

#ifdef __linux__ 
		usleep(1000);
#else
		Sleep(1);
#endif
	}

	free(tx_buf);
	free(rx_buf);

	return 0;
} 
예제 #22
0
파일: main.c 프로젝트: Drooids/nrf
int main(void)
{
  uint8_t tx_addr[4] = { 0xaa, 0xab, 0xac, 0xad };
  uint8_t rx_addr[4] = { 0xa1, 0xa2, 0xa3, 0xa4 };

  sys_setup();

  uart_setup();

  /* setup spi first */
  spi_setup_master();
  spi_set_sck_freq(SPI_SCK_FREQ_FOSC2);

  nrf905_setup();
  nrf905_set_tx_addr(tx_addr, 4);
  nrf905_set_rx_addr(rx_addr, 4);
  nrf905_set_payload_width(2);
  nrf905_commit_config();

#if 0
  {
    uint8_t i;
    dump_config();
    for (i = 0; i != sizeof(nrf905_config); ++i)
      nrf905_config[i] = 0x2a;
    nrf905_cmd_rc();
    dump_config();
  }
#endif

#if 0
  {
    uint8_t x;
    uart_write((uint8_t*)"rx side\r\n", 9);
    uart_write((uint8_t*)"press space\r\n", 13);
    uart_read_uint8(&x);
    uart_write((uint8_t*)"starting\r\n", 10);
  }
#endif

  led_setup();

  nrf905_set_rx();

  while (1)
  {
  wait_cd:
    if (nrf905_is_cd() == 0)
    {
      led_set(LED_RED);
      while (nrf905_is_cd() == 0) ;
      /* uart_write((uint8_t*)"cd\r\n", 4); */
    }

#if 0
    while (nrf905_is_am() == 0) ;
    uart_write((uint8_t*)"am\r\n", 4);
    led_mask = LED_GREEN;
#endif

    led_set(LED_GREEN);

  wait_dr:
    while (nrf905_is_dr() == 0)
    {
      if (nrf905_is_cd() == 0) goto wait_cd;
    }
    uart_write((uint8_t*)"dr\r\n", 4);

    reset_pattern();

    /* wait(); */
    nrf905_read_payload();

    if (check_pattern() == 0)
    {
      uart_write((uint8_t*)"ok\r\n", 4);
      led_set(LED_BLUE);
    }
    else led_set(LED_GREEN);

    goto wait_dr;
  }

  return 0;
}
예제 #23
0
/**
 * ubi_io_read_vid_hdr - read and check a volume identifier header.
 * @ubi: UBI device description object
 * @pnum: physical eraseblock number to read from
 * @vid_hdr: &struct ubi_vid_hdr object where to store the read volume
 * identifier header
 * @verbose: be verbose if the header is corrupted or wasn't found
 *
 * This function reads the volume identifier header from physical eraseblock
 * @pnum and stores it in @vid_hdr. It also checks CRC checksum of the read
 * volume identifier header. The following codes may be returned:
 *
 * o %0 if the CRC checksum is correct and the header was successfully read;
 * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected
 *   and corrected by the flash driver; this is harmless but may indicate that
 *   this eraseblock may become bad soon;
 * o %UBI_IO_BAD_VID_HDR if the volume identifier header is corrupted (a CRC
 *   error detected);
 * o %UBI_IO_PEB_FREE if the physical eraseblock is free (i.e., there is no VID
 *   header there);
 * o a negative error code in case of failure.
 */
int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
			struct ubi_vid_hdr *vid_hdr, int verbose)
{
	int err, read_err = 0;
	uint32_t crc, magic, hdr_crc;
	void *p;

	dbg_io("read VID header from PEB %d", pnum);
	ubi_assert(pnum >= 0 &&  pnum < ubi->peb_count);

	p = (char *)vid_hdr - ubi->vid_hdr_shift;
	err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset,
			  ubi->vid_hdr_alsize);
	if (err) {
		if (err != UBI_IO_BITFLIPS && err != -EBADMSG)
			return err;

		/*
		 * We read all the data, but either a correctable bit-flip
		 * occurred, or MTD reported about some data integrity error,
		 * like an ECC error in case of NAND. The former is harmless,
		 * the later may mean the read data is corrupted. But we have a
		 * CRC check-sum and we will identify this. If the VID header is
		 * still OK, we just report this as there was a bit-flip.
		 */
		read_err = err;
	}

	magic = be32_to_cpu(vid_hdr->magic);
	if (magic != UBI_VID_HDR_MAGIC) {
		/*
		 * If we have read all 0xFF bytes, the VID header probably does
		 * not exist and the physical eraseblock is assumed to be free.
		 *
		 * But if there was a read error, we do not test the data for
		 * 0xFFs. Even if it does contain all 0xFFs, this error
		 * indicates that something is still wrong with this physical
		 * eraseblock and it cannot be regarded as free.
		 */
		if (read_err != -EBADMSG &&
		    check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
			/* The physical eraseblock is supposedly free */
			if (verbose)
				ubi_warn("no VID header found at PEB %d, "
					 "only 0xFF bytes", pnum);
			else if (UBI_IO_DEBUG)
				dbg_msg("no VID header found at PEB %d, "
					"only 0xFF bytes", pnum);
			return UBI_IO_PEB_FREE;
		}

		/*
		 * This is not a valid VID header, and these are not 0xFF
		 * bytes. Report that the header is corrupted.
		 */
		if (verbose) {
			ubi_warn("bad magic number at PEB %d: %08x instead of "
				 "%08x", pnum, magic, UBI_VID_HDR_MAGIC);
			ubi_dbg_dump_vid_hdr(vid_hdr);
		} else if (UBI_IO_DEBUG)
			dbg_msg("bad magic number at PEB %d: %08x instead of "
				"%08x", pnum, magic, UBI_VID_HDR_MAGIC);
		return UBI_IO_BAD_VID_HDR;
	}

	crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC);
	hdr_crc = be32_to_cpu(vid_hdr->hdr_crc);

	if (hdr_crc != crc) {
		if (verbose) {
			ubi_warn("bad CRC at PEB %d, calculated %#08x, "
				 "read %#08x", pnum, crc, hdr_crc);
			ubi_dbg_dump_vid_hdr(vid_hdr);
		} else if (UBI_IO_DEBUG)
			dbg_msg("bad CRC at PEB %d, calculated %#08x, "
				"read %#08x", pnum, crc, hdr_crc);
		return UBI_IO_BAD_VID_HDR;
	}

	/* Validate the VID header that we have just read */
	err = validate_vid_hdr(ubi, vid_hdr);
	if (err) {
		ubi_err("validation failed for PEB %d", pnum);
		return -EINVAL;
	}

	return read_err ? UBI_IO_BITFLIPS : 0;
}
예제 #24
0
/**
 * ubi_io_read_ec_hdr - read and check an erase counter header.
 * @ubi: UBI device description object
 * @pnum: physical eraseblock to read from
 * @ec_hdr: a &struct ubi_ec_hdr object where to store the read erase counter
 * header
 * @verbose: be verbose if the header is corrupted or was not found
 *
 * This function reads erase counter header from physical eraseblock @pnum and
 * stores it in @ec_hdr. This function also checks CRC checksum of the read
 * erase counter header. The following codes may be returned:
 *
 * o %0 if the CRC checksum is correct and the header was successfully read;
 * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected
 *   and corrected by the flash driver; this is harmless but may indicate that
 *   this eraseblock may become bad soon (but may be not);
 * o %UBI_IO_BAD_EC_HDR if the erase counter header is corrupted (a CRC error);
 * o %UBI_IO_PEB_EMPTY if the physical eraseblock is empty;
 * o a negative error code in case of failure.
 */
int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
		       struct ubi_ec_hdr *ec_hdr, int verbose)
{
	int err, read_err = 0;
	uint32_t crc, magic, hdr_crc;

	dbg_io("read EC header from PEB %d", pnum);
	ubi_assert(pnum >= 0 && pnum < ubi->peb_count);

	err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE);
	if (err) {
		if (err != UBI_IO_BITFLIPS && err != -EBADMSG)
			return err;

		/*
		 * We read all the data, but either a correctable bit-flip
		 * occurred, or MTD reported about some data integrity error,
		 * like an ECC error in case of NAND. The former is harmless,
		 * the later may mean that the read data is corrupted. But we
		 * have a CRC check-sum and we will detect this. If the EC
		 * header is still OK, we just report this as there was a
		 * bit-flip.
		 */
		read_err = err;
	}

	magic = be32_to_cpu(ec_hdr->magic);
	if (magic != UBI_EC_HDR_MAGIC) {
		/*
		 * The magic field is wrong. Let's check if we have read all
		 * 0xFF. If yes, this physical eraseblock is assumed to be
		 * empty.
		 *
		 * But if there was a read error, we do not test it for all
		 * 0xFFs. Even if it does contain all 0xFFs, this error
		 * indicates that something is still wrong with this physical
		 * eraseblock and we anyway cannot treat it as empty.
		 */
		if (read_err != -EBADMSG &&
		    check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) {
			/* The physical eraseblock is supposedly empty */
			if (verbose)
				ubi_warn("no EC header found at PEB %d, "
					 "only 0xFF bytes", pnum);
			else if (UBI_IO_DEBUG)
				dbg_msg("no EC header found at PEB %d, "
					"only 0xFF bytes", pnum);
			return UBI_IO_PEB_EMPTY;
		}

		/*
		 * This is not a valid erase counter header, and these are not
		 * 0xFF bytes. Report that the header is corrupted.
		 */
		if (verbose) {
			ubi_warn("bad magic number at PEB %d: %08x instead of "
				 "%08x", pnum, magic, UBI_EC_HDR_MAGIC);
			ubi_dbg_dump_ec_hdr(ec_hdr);
		} else if (UBI_IO_DEBUG)
			dbg_msg("bad magic number at PEB %d: %08x instead of "
				"%08x", pnum, magic, UBI_EC_HDR_MAGIC);
		return UBI_IO_BAD_EC_HDR;
	}

	crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
	hdr_crc = be32_to_cpu(ec_hdr->hdr_crc);

	if (hdr_crc != crc) {
		if (verbose) {
			ubi_warn("bad EC header CRC at PEB %d, calculated "
				 "%#08x, read %#08x", pnum, crc, hdr_crc);
			ubi_dbg_dump_ec_hdr(ec_hdr);
		} else if (UBI_IO_DEBUG)
			dbg_msg("bad EC header CRC at PEB %d, calculated "
				"%#08x, read %#08x", pnum, crc, hdr_crc);
		return UBI_IO_BAD_EC_HDR;
	}

	/* And of course validate what has just been read from the media */
	err = validate_ec_hdr(ubi, ec_hdr);
	if (err) {
		ubi_err("validation failed for PEB %d", pnum);
		return -EINVAL;
	}

	return read_err ? UBI_IO_BITFLIPS : 0;
}
예제 #25
0
/**
 * torture_peb - test a supposedly bad physical eraseblock.
 * @ubi: UBI device description object
 * @pnum: the physical eraseblock number to test
 *
 * This function returns %-EIO if the physical eraseblock did not pass the
 * test, a positive number of erase operations done if the test was
 * successfully passed, and other negative error codes in case of other errors.
 */
static int torture_peb(struct ubi_device *ubi, int pnum)
{
	int err, i, patt_count;

	ubi_msg("run torture test for PEB %d", pnum);
	patt_count = ARRAY_SIZE(patterns);
	ubi_assert(patt_count > 0);

	mutex_lock(&ubi->buf_mutex);
	for (i = 0; i < patt_count; i++) {
		err = do_sync_erase(ubi, pnum);
		if (err)
			goto out;

		/* Make sure the PEB contains only 0xFF bytes */
		err = ubi_io_read(ubi, ubi->peb_buf1, pnum, 0, ubi->peb_size);
		if (err)
			goto out;

		err = check_pattern(ubi->peb_buf1, 0xFF, ubi->peb_size);
		if (err == 0) {
			ubi_err("erased PEB %d, but a non-0xFF byte found",
				pnum);
			err = -EIO;
			goto out;
		}

		/* Write a pattern and check it */
		memset(ubi->peb_buf1, patterns[i], ubi->peb_size);
		err = ubi_io_write(ubi, ubi->peb_buf1, pnum, 0, ubi->peb_size);
		if (err)
			goto out;

		memset(ubi->peb_buf1, ~patterns[i], ubi->peb_size);
		err = ubi_io_read(ubi, ubi->peb_buf1, pnum, 0, ubi->peb_size);
		if (err)
			goto out;

		err = check_pattern(ubi->peb_buf1, patterns[i], ubi->peb_size);
		if (err == 0) {
			ubi_err("pattern %x checking failed for PEB %d",
				patterns[i], pnum);
			err = -EIO;
			goto out;
		}
	}

	err = patt_count;
	ubi_msg("PEB %d passed torture test, do not mark it a bad", pnum);

out:
	mutex_unlock(&ubi->buf_mutex);
	if (err == UBI_IO_BITFLIPS || err == -EBADMSG) {
		/*
		 * If a bit-flip or data integrity error was detected, the test
		 * has not passed because it happened on a freshly erased
		 * physical eraseblock which means something is wrong with it.
		 */
		ubi_err("read problems on freshly erased PEB %d, must be bad",
			pnum);
		err = -EIO;
	}
	return err;
}
예제 #26
0
static int
rangematch(const char *pattern, char test, int flags, const char **newp)
{
    int negate, ok;
    char c, c2;
    char tmp;

    /*
     * A bracket expression starting with an unquoted circumflex
     * character produces unspecified results (IEEE 1003.2-1992,
     * 3.13.2).  This implementation treats it like '!', for
     * consistency with the regular expression syntax.
     * J.T. Conklin ([email protected])
     */
    if ((negate = (*pattern == '!' || *pattern == '^')))
        ++pattern;

    if (check_flag(flags, WM_CASEFOLD))
        test = tolower((unsigned char)test);

    /*
     * A right bracket shall lose its special meaning and represent
     * itself in a bracket expression if it occurs first in the list.
     * -- POSIX.2 2.8.3.2
     */
    ok = 0;
    c = *pattern++;
    do {
        if (c == '\\' && !check_flag(flags, WM_NOESCAPE))
            c = *pattern++;

        if (c == EOS)
            return RANGE_ERROR;

        if (c == '/' && check_flag(flags, WM_PATHNAME))
            return RANGE_NOMATCH;

        if (*pattern == '-'
            && (c2 = *(pattern+1)) != EOS && c2 != ']') {
            pattern += 2;
            if (c2 == '\\' && !check_flag(flags, WM_NOESCAPE))
                c2 = *pattern++;
            if (c2 == EOS)
                return RANGE_ERROR;

            if (check_flag(flags, WM_CASEFOLD)) {
                c = tolower((unsigned char)c);
                c2 = tolower((unsigned char)c2);
            }
            if (c > c2) {
                tmp = c2;
                c2 = c;
                c = tmp;
            }
            if (c <= test && test <= c2) {
                ok = 1;
            }
        }

        if (c == '[' && *pattern == ':' && *(pattern+1) != EOS) {

            #define match_pattern(name) \
                !strncmp(pattern+1, name, sizeof(name)-1)

            #define check_pattern(name, predicate, value) {{ \
                if (match_pattern(name ":]")) { \
                    if (predicate(value)) { \
                        ok = 1; \
                    } \
                    pattern += sizeof(name ":]"); \
                    continue; \
                } \
            }}

            if (match_pattern(":]")) {
                continue;
            }
            check_pattern("alnum", isalnum, test);
            check_pattern("alpha", isalpha, test);
            check_pattern("blank", isblank, test);
            check_pattern("cntrl", iscntrl, test);
            check_pattern("digit", isdigit, test);
            check_pattern("graph", isgraph, test);
            check_pattern("lower", islower, test);
            check_pattern("print", isprint, test);
            check_pattern("punct", ispunct, test);
            check_pattern("space", isspace, test);
            check_pattern("xdigit", isxdigit, test);
            c2 = check_flag(flags, WM_CASEFOLD) ? toupper(test) : test;
            check_pattern("upper", isupper, c2);
            /* fallthrough means match like a normal character */
        }
        if (c == test) {
            ok = 1;
        }
    } while ((c = *pattern++) != ']');

    *newp = (const char *)pattern;
    return (ok == negate) ? RANGE_NOMATCH : RANGE_MATCH;
}
예제 #27
0
void process_multipart_for_upgrade(http_req *req)
{
	char *startp, *strp;
	char *boundary;
	char *varname;
	int remain_len;
	
	
	boundary = strstr(req->content_type, "boundary=");
	boundary += 9;
    //here,req->request[req->request_idx] has copy into req->content->buf
    //but we can't parse req->content->buf, the buf will be use next part for send response to browser.
    //so for image upgrade,we parse req->request[req->request_idx] for it not used in other parts after parse reuqest header.
    //this function only use for http_read firstly,and only for image upgrade.
	startp = &(req->request[req->request_idx]);
	remain_len = req->content->len;
	
	while(remain_len > 0) 
	{
		if((startp = check_pattern(startp, remain_len, boundary)) == NULL )
			break;
	
		if(startp-4 > &(req->request[req->request_idx]))
			*(startp-4) = '\0'; /* \r\n-- */	//comment by haitao:add end char '\0'  for value.
		
		startp += strlen(boundary);
		
		if(*startp=='-' && *(startp+1)=='-')
			break;  /* end */ /* Roger: This check method is right?? */
		
		startp +=2;
		
		remain_len = req->content->len - (startp - &(req->request[req->request_idx]));
		if (!strncasecmp(startp, "Content-Disposition:", 20) ) 
		{
			if((varname = check_pattern(startp, remain_len, "name=\"")) != NULL ) 
			{
					
				/* find out begin of file */
		    	if((strp = check_pattern(startp, remain_len, "\r\n\r\n")) != NULL) 
		    	{
		    		startp = strp+4;
		    	}
		    	else if((strp = check_pattern(startp, remain_len, "\n\n")) != NULL) 
		    	{
		    		startp = strp+2;
		    	}
		    	else 
		    	{
		    		diag_printf("Can not find value of %s\n", varname);
		    		return;
		    	}
		    	varname += 6;
		    	strp = strchr( varname, '"');	
		    	*strp =  '\0';//comment by haitao:replace '"' with '\0',to add end char for name.
		    	query_set(req, varname, startp);	
		    }
		}
		remain_len =  req->content->len -(startp - &(req->request[req->request_idx]));
	}
}
예제 #28
0
/*
 * Builds the dependency list (aka stack) of a module.
 * head: the highest module in the stack (last to insmod, first to rmmod)
 * tail: the lowest module in the stack (first to insmod, last to rmmod)
 */
static void check_dep(char *mod, struct mod_list_t **head, struct mod_list_t **tail)
{
	struct mod_list_t *find;
	struct dep_t *dt;
	struct mod_opt_t *opt = NULL;
	char *path = NULL;

	/* Search for the given module name amongst all dependency rules.
	 * The module name in a dependency rule can be a shell pattern,
	 * so try to match the given module name against such a pattern.
	 * Of course if the name in the dependency rule is a plain string,
	 * then we consider it a pattern, and matching will still work. */
	for (dt = depend; dt; dt = dt->m_next) {
		if (check_pattern(dt->m_name, mod) == 0) {
			break;
		}
	}

	if (!dt) {
		bb_error_msg("module %s not found", mod);
		return;
	}

	// resolve alias names
	while (dt->m_isalias) {
		if (dt->m_depcnt == 1) {
			struct dep_t *adt;

			for (adt = depend; adt; adt = adt->m_next) {
				if (check_pattern(adt->m_name, dt->m_deparr[0]) == 0 &&
						!(ENABLE_FEATURE_MODPROBE_BLACKLIST &&
							adt->m_isblacklisted))
					break;
			}
			if (adt) {
				/* This is the module we are aliased to */
				struct mod_opt_t *opts = dt->m_options;
				/* Option of the alias are appended to the options of the module */
				while (opts) {
					adt->m_options = append_option(adt->m_options, opts->m_opt_val);
					opts = opts->m_next;
				}
				dt = adt;
			} else {
				bb_error_msg("module %s not found", mod);
				return;
			}
		} else {
			bb_error_msg("bad alias %s", dt->m_name);
			return;
		}
	}

	mod = dt->m_name;
	path = dt->m_path;
	opt = dt->m_options;

	// search for duplicates
	for (find = *head; find; find = find->m_next) {
		if (strcmp(mod, find->m_name) == 0) {
			// found -> dequeue it

			if (find->m_prev)
				find->m_prev->m_next = find->m_next;
			else
				*head = find->m_next;

			if (find->m_next)
				find->m_next->m_prev = find->m_prev;
			else
				*tail = find->m_prev;

			break; // there can be only one duplicate
		}
	}

	if (!find) { // did not find a duplicate
		find = xzalloc(sizeof(struct mod_list_t));
		find->m_name = mod;
		find->m_path = path;
		find->m_options = opt;
	}

	// enqueue at tail
	if (*tail)
		(*tail)->m_next = find;
	find->m_prev = *tail;
	find->m_next = NULL; /* possibly NOT done by xzalloc! */

	if (!*head)
		*head = find;
	*tail = find;

	if (dt) {
		int i;

		/* Add all dependable module for that new module */
		for (i = 0; i < dt->m_depcnt; i++)
			check_dep(dt->m_deparr[i], head, tail);
	}
}