Exemplo n.º 1
0
static char *cache_record_serialize (const struct cache_record *rec, int *len)
{
	char *buf;
	char *p;
	size_t artist_len;
	size_t album_len;
	size_t title_len;


	artist_len = strlen_null (rec->tags->artist);
	album_len = strlen_null (rec->tags->album);
	title_len = strlen_null (rec->tags->title);

	*len = sizeof(rec->mod_time)
		+ sizeof(rec->atime)
		+ sizeof(size_t) * 3 /* lengths of title, artist, time. */
		+ artist_len
		+ album_len
		+ title_len
		+ sizeof(rec->tags->track)
		+ sizeof(rec->tags->time);

	buf = p = (char *)xmalloc (*len);

	memcpy (p, &rec->mod_time, sizeof(rec->mod_time));
	p += sizeof(rec->mod_time);

	memcpy (p, &rec->atime, sizeof(rec->atime));
	p += sizeof(rec->atime);

	memcpy (p, &artist_len, sizeof(artist_len));
	p += sizeof(artist_len);
	if (artist_len) {
		memcpy (p, rec->tags->artist, artist_len);
		p += artist_len;
	}

	memcpy (p, &album_len, sizeof(album_len));
	p += sizeof(album_len);
	if (album_len) {
		memcpy (p, rec->tags->album, album_len);
		p += album_len;
	}

	memcpy (p, &title_len, sizeof(title_len));
	p += sizeof(title_len);
	if (title_len) {
		memcpy (p, rec->tags->title, title_len);
		p += title_len;
	}

	memcpy (p, &rec->tags->track, sizeof(rec->tags->track));
	p += sizeof(rec->tags->track);

	memcpy (p, &rec->tags->time, sizeof(rec->tags->time));
	p += sizeof(rec->tags->time);

	return buf;
}
Exemplo n.º 2
0
noinline int do_action(const char* arg) {
    // Prefixes.
    if (!strncmp(arg, "wait-", strlen("wait-"))) {
      char buf[1];
      TEMP_FAILURE_RETRY(read(STDIN_FILENO, buf, sizeof(buf)));
      return do_action(arg + strlen("wait-"));
    } else if (!strncmp(arg, "exhaustfd-", strlen("exhaustfd-"))) {
      errno = 0;
      while (errno != EMFILE) {
        open("/dev/null", O_RDONLY);
      }
      return do_action(arg + strlen("exhaustfd-"));
    } else if (!strncmp(arg, "thread-", strlen("thread-"))) {
        return do_action_on_thread(arg + strlen("thread-"));
    }

    // Actions.
    if (!strcasecmp(arg, "SIGSEGV-non-null")) {
        sigsegv_non_null();
    } else if (!strcasecmp(arg, "smash-stack")) {
        volatile int len = 128;
        return smash_stack(&len);
    } else if (!strcasecmp(arg, "stack-overflow")) {
        overflow_stack(nullptr);
    } else if (!strcasecmp(arg, "nostack")) {
        crashnostack();
    } else if (!strcasecmp(arg, "exit")) {
        exit(1);
    } else if (!strcasecmp(arg, "crash") || !strcmp(arg, "SIGSEGV")) {
        return crash(42);
    } else if (!strcasecmp(arg, "abort")) {
        maybe_abort();
    } else if (!strcasecmp(arg, "assert")) {
        __assert("some_file.c", 123, "false");
    } else if (!strcasecmp(arg, "assert2")) {
        __assert2("some_file.c", 123, "some_function", "false");
    } else if (!strcasecmp(arg, "fortify")) {
        char buf[10];
        __read_chk(-1, buf, 32, 10);
        while (true) pause();
    } else if (!strcasecmp(arg, "LOG(FATAL)")) {
        LOG(FATAL) << "hello " << 123;
    } else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL")) {
        LOG_ALWAYS_FATAL("hello %s", "world");
    } else if (!strcasecmp(arg, "LOG_ALWAYS_FATAL_IF")) {
        LOG_ALWAYS_FATAL_IF(true, "hello %s", "world");
    } else if (!strcasecmp(arg, "SIGFPE")) {
        raise(SIGFPE);
        return EXIT_SUCCESS;
    } else if (!strcasecmp(arg, "SIGTRAP")) {
        raise(SIGTRAP);
        return EXIT_SUCCESS;
    } else if (!strcasecmp(arg, "fprintf-NULL")) {
        fprintf_null();
    } else if (!strcasecmp(arg, "readdir-NULL")) {
        readdir_null();
    } else if (!strcasecmp(arg, "strlen-NULL")) {
        return strlen_null();
    } else if (!strcasecmp(arg, "pthread_join-NULL")) {
        return pthread_join(0, nullptr);
    } else if (!strcasecmp(arg, "heap-usage")) {
        abuse_heap();
    } else if (!strcasecmp(arg, "leak")) {
        leak();
    } else if (!strcasecmp(arg, "SIGSEGV-unmapped")) {
        char* map = reinterpret_cast<char*>(mmap(nullptr, sizeof(int), PROT_READ | PROT_WRITE,
                                                 MAP_SHARED | MAP_ANONYMOUS, -1, 0));
        munmap(map, sizeof(int));
        map[0] = '8';
    } else if (!strcasecmp(arg, "seccomp")) {
        set_seccomp_filter();
        syscall(99999);
#if defined(__arm__)
    } else if (!strcasecmp(arg, "kuser_helper_version")) {
        return __kuser_helper_version;
    } else if (!strcasecmp(arg, "kuser_get_tls")) {
        return !__kuser_get_tls();
    } else if (!strcasecmp(arg, "kuser_cmpxchg")) {
        return __kuser_cmpxchg(0, 0, 0);
    } else if (!strcasecmp(arg, "kuser_memory_barrier")) {
        __kuser_dmb();
    } else if (!strcasecmp(arg, "kuser_cmpxchg64")) {
        return __kuser_cmpxchg64(0, 0, 0);
#endif
    } else if (!strcasecmp(arg, "no_new_privs")) {
        if (prctl(PR_SET_NO_NEW_PRIVS, 1) != 0) {
          fprintf(stderr, "prctl(PR_SET_NO_NEW_PRIVS, 1) failed: %s\n", strerror(errno));
          return EXIT_SUCCESS;
        }
        abort();
    } else {
        return usage();
    }

    fprintf(stderr, "%s: exiting normally!\n", getprogname());
    return EXIT_SUCCESS;
}