Exemplo n.º 1
0
static void assert_strlen (uword iter)
{
  u8 * s;
  void * s_orig;
  uword i, size, unalign, offset, len;
  u8 c;

  for (i = 0; i < iter; i++)
    {
      size = bounded_random_u32 (&g_seed, 0, g_bytes);
      size++;
      unalign = bounded_random_u32 (&g_seed, 0, 1);

      if (unalign)
	{
	  offset = bounded_random_u32 (&g_seed, 0, 7);
	  s = alloc_unaligned (size, offset, &s_orig);
	}
      else
	{
	  s = alloc_aligned (size, g_align, &s_orig);
	}
	 
      c = bounded_random_u32 (&g_seed, 0, 255);
      memset (s, c, size - 1);
      s[size - 1] = '\0';
      
      len = strlen8 (s);
      ASSERT (len == strlen (s));

      clib_mem_free_safe (s_orig);
    }

  fformat (stdout, "strlen() validation successful!\n");
}
Exemplo n.º 2
0
void chartou32(char* str, u32* o)
{
	int i;
	int len = strlen8(str);
	for(i = 0; i < len; i++)
		o[i] = str[i];
	o[i] = 0;
}
Exemplo n.º 3
0
void log_guess(char *login, char *uid, char *ciphertext, char *rep_plain,
               char *store_plain, char field_sep, int index)
{
	int count1, count2;
	int len;
	char spacer[] = "                ";
	char *secret = "";
	char uid_sep[2] = { 0 };
	char *uid_out = "";

/* This is because printf("%-16s") does not line up multibyte UTF-8.
   We need to count characters, not octets. */
	if (pers_opts.target_enc == UTF_8 || pers_opts.report_utf8)
		len = strlen8((UTF8*)rep_plain);
	else
		len = strlen(rep_plain);

	if (options.show_uid_on_crack && uid && *uid) {
		uid_sep[0] = field_sep;
		uid_out = uid;
	}

	if (options.verbosity > 1) {
		if (options.secure) {
			secret = components(rep_plain, len);
			printf("%-16s (%s%s%s)\n",
			       secret, login, uid_sep, uid_out);
		} else {
			spacer[len > 16 ? 0 : 16 - len] = 0;

			printf("%s%s (%s%s%s)\n",
			       rep_plain, spacer, login, uid_sep, uid_out);

			if (options.fork)
				fflush(stdout);
		}
	}

	in_logger = 1;

	if (pot.fd >= 0 && ciphertext ) {
#ifndef DYNAMIC_DISABLED
		if (!strncmp(ciphertext, "$dynamic_", 9))
			ciphertext = dynamic_FIX_SALT_TO_HEX(ciphertext);
#endif
		if (strlen(ciphertext) + strlen(store_plain) <= LINE_BUFFER_SIZE - 3) {
			if (options.secure) {
				secret = components(store_plain, len);
				count1 = (int)sprintf(pot.ptr,
				                      "%s%c%s\n",
				                      ciphertext,
				                      field_sep,
				                      secret);
			} else
				count1 = (int)sprintf(pot.ptr,
				                      "%s%c%s\n", ciphertext,
				                      field_sep, store_plain);
			if (count1 > 0) pot.ptr += count1;
		}
	}

	if (log.fd >= 0 &&
	    strlen(login) < LINE_BUFFER_SIZE - 64) {
		count1 = log_time();
		if (count1 > 0) {
			log.ptr += count1;
			count2 = (int)sprintf(log.ptr, "+ Cracked %s%s%s", login, uid_sep, uid_out);

			if (options.secure) {
				secret = components(rep_plain, len);
				count2 += (int)sprintf(log.ptr + count2,
				                       ": %s", secret);
			} else
			if (cfg_log_passwords)
				count2 += (int)sprintf(log.ptr + count2,
				                       ": %s", rep_plain);
			if (cfg_showcand)
				count2 += (int)sprintf(log.ptr + count2,
				                       " as candidate #"LLu"",
				                       ((unsigned long long)
				                       status.cands.hi << 32) +
				                       status.cands.lo + index + 1);
			count2 += (int)sprintf(log.ptr + count2, "\n");

			if (count2 > 0)
				log.ptr += count2;
			else
				log.ptr -= count1;
		}
	}

/* Try to keep the two files in sync */
	if (log_file_write(&pot))
		log_file_flush(&log);
	else
	if (log_file_write(&log))
		log_file_flush(&pot);

	in_logger = 0;

	if (cfg_beep)
		write_loop(fileno(stderr), "\007", 1);
}
Exemplo n.º 4
0
void log_guess(char *login, char *ciphertext, char *rep_plain, char *store_plain, char field_sep)
{
	int count1, count2;
	int len;
	char spacer[] = "                ";

	// This is because printf("%-16s") does not line up multibyte UTF-8.
	// We need to count characters, not octets.
	if (options.utf8 || options.report_utf8)
		len = strlen8((UTF8*)rep_plain);
	else
		len = strlen(rep_plain);
	spacer[len > 16 ? 0 : 16 - len] = 0;

#ifdef HAVE_MPI
	// All but node 0 has stdout closed so we output to stderr
	if (mpi_p > 1)
		fprintf(stderr, "%s%s (%s)\n", rep_plain, spacer, login);
	else
#endif
		printf("%s%s (%s)\n", rep_plain, spacer, login);

	in_logger = 1;

	if (pot.fd >= 0 && ciphertext ) {
		if (!strncmp(ciphertext, "$dynamic_", 9))
			ciphertext = dynamic_FIX_SALT_TO_HEX(ciphertext);
		if (strlen(ciphertext) + strlen(store_plain) <= LINE_BUFFER_SIZE - 3) {
			count1 = (int)sprintf(pot.ptr,
				"%s%c%s\n", ciphertext, field_sep, store_plain);
			if (count1 > 0) pot.ptr += count1;
		}
	}

	if (log.fd >= 0 &&
	    strlen(login) < LINE_BUFFER_SIZE - 64) {
		count1 = log_time();
		if (count1 > 0) {
			log.ptr += count1;
			if (cfg_log_passwords)
				count2 = (int)sprintf(log.ptr,
				    "+ Cracked %s: %s\n", login, rep_plain);
			else
				count2 = (int)sprintf(log.ptr,
				    "+ Cracked %s\n", login);
			if (count2 > 0)
				log.ptr += count2;
			else
				log.ptr -= count1;
		}
	}

/* Try to keep the two files in sync */
	if (log_file_write(&pot))
		log_file_flush(&log);
	else
	if (log_file_write(&log))
		log_file_flush(&pot);

	in_logger = 0;

	if (cfg_beep)
		write_loop(fileno(stderr), "\007", 1);
}