コード例 #1
0
void
_libc_fork_child(void)
{
	CRSetCrashLogMessage("crashed on child side of fork pre-exec");

	_arc4_fork_child();
#if !TARGET_IPHONE_SIMULATOR
	_init_clock_port();
#endif
	_dirhelper_fork_child();
}
コード例 #2
0
void
__pthread_abort_reason(const char *fmt, ...)
{
#if !TARGET_OS_EMBEDDED
	va_list ap;
	const char *str = fmt;
	_SIMPLE_STRING s = _simple_salloc();
	va_start(ap, fmt);
	if (_simple_vsprintf(s, fmt, ap) == 0) {
		str = _simple_string(s);
	}
	CRSetCrashLogMessage(str);
	va_end(ap);
#endif
	__pthread_abort();
}
コード例 #3
0
ファイル: rpcsvc.c プロジェクト: HumbleRepose/dcerpc
void rpc_dce_svc_printf (
                        const char* file,
                        unsigned int line,
                        const char *format,
                        unsigned32 dbg_switch ATTRIBUTE_UNUSED,
                        unsigned32 sev_action_flags,
                        unsigned32 error_code,
                        ... )
{
    char buff[1024];
    char *s = buff;
    size_t remain = sizeof(buff);
    va_list arg_ptr;
    int cs;

    snprintf (s, remain, "[file %s, line %d] ", file, line);
    s = &buff[strlen(buff)];
    remain = sizeof(buff) - (s - buff);

    snprintf (s, remain, "[flags: 0x%x] ", (unsigned int) sev_action_flags);
    s = &buff[strlen(buff)];
    remain = sizeof(buff) - (s - buff);

    snprintf (s, remain, "[error: 0x%x] ", (unsigned int) error_code);
    s = &buff[strlen(buff)];
    remain = sizeof(buff) - (s - buff);

    va_start (arg_ptr, error_code);
    vsnprintf (s, remain, format, arg_ptr);
    va_end (arg_ptr);

    if ( (sev_action_flags & svc_c_action_abort) ||
        (sev_action_flags & svc_c_action_exit_bad) )
    {
        CRSetCrashLogMessage(buff);
        abort();
    }
    else
    {
        cs = dcethread_enableinterrupt_throw(0);
        dcethread_write (2, buff, strlen (buff));
        dcethread_enableinterrupt_throw(cs);
    }
}
コード例 #4
0
int check_and_gen_key(const char *key_type, char *envp[])
{
    char path[PATH_MAX];
    char *key = strdup(key_type);
    struct stat s;

    snprintf(path, sizeof(path), "%s/ssh_host_%s_key", SSHDIR, key_type);
    if (0 != stat(path, &s)) {
        pid_t child;

        char *argv[] = { "/usr/bin/ssh-keygen",
                          "-q",
                          "-t", key,
                          "-f", path,
                          "-N", "",
                          "-C", "",
                          0
                       };

        child = fork();
        if (child == 0) {
            int ret;
            char msg[1024];

            if (!freopen("/dev/null", "w", stdout)) {
                syslog(LOG_ERR, "failed to redirect stdout for ssh-keygen operation");
            }
            ret = execve(argv[0], &argv[0], envp);
            snprintf(msg, sizeof(msg), "execve failed on error %d %d: %s: /usr/bin/sshd-keygen -q -t %s -f %s -N \"\" -C \"\"", ret, errno, strerror(errno), key, path);
            CRSetCrashLogMessage(msg);
            abort();
        } else {
            pid_t tpid;
            int stat_loc;
            do {
                tpid = waitpid(child, &stat_loc, 0);
            } while (tpid != child);
        }
    }

    free(key);
    return 0;
}
コード例 #5
0
ファイル: Errors.cpp プロジェクト: Saisi/swift
// Report a message to any forthcoming crash log.
static void
reportOnCrash(uint32_t flags, const char *message)
{
  static pthread_mutex_t crashlogLock = PTHREAD_MUTEX_INITIALIZER;
  pthread_mutex_lock(&crashlogLock);
  
  char *oldMessage = (char *)CRGetCrashLogMessage();

  char *newMessage;
  if (oldMessage) {
    asprintf(&newMessage, "%s%s", oldMessage, message);
    if (malloc_size(oldMessage)) free(oldMessage);
  } else {
    newMessage = strdup(message);
  }

  CRSetCrashLogMessage(newMessage);

  pthread_mutex_unlock(&crashlogLock);
}
コード例 #6
0
CF_PRIVATE CFTypeRef __CFCreateOldStylePropertyListOrStringsFile(CFAllocatorRef allocator, CFDataRef xmlData, CFStringRef originalString, CFStringEncoding guessedEncoding, CFOptionFlags option, CFErrorRef *outError,CFPropertyListFormat *format) {
    
    // Convert the string to UTF16 for parsing old-style
    if (originalString) {
        // Ensure that originalString is not collected while we are using it
        CFRetain(originalString);
    } else {
        originalString = CFStringCreateWithBytes(kCFAllocatorSystemDefault, CFDataGetBytePtr(xmlData), CFDataGetLength(xmlData), guessedEncoding, NO);
        if (!originalString) {
            // Couldn't convert
            if (outError) *outError = __CFPropertyListCreateError(kCFPropertyListReadCorruptError, CFSTR("Conversion of string failed."));
            return NULL;
        }
    }
        
    UInt32 length;
    Boolean createdBuffer = false;
    length = CFStringGetLength(originalString);
    if (!length) {
        if (outError) *outError = __CFPropertyListCreateError(kCFPropertyListReadCorruptError, CFSTR("Conversion of string failed. The string is empty."));
        return NULL;
    }
    
    UniChar *buf = (UniChar *)CFStringGetCharactersPtr(originalString);
    if (!buf) {
        buf = (UniChar *)CFAllocatorAllocate(allocator, length * sizeof(UniChar), 0);
        if (!buf) {
            CRSetCrashLogMessage("CFPropertyList ran out of memory while attempting to allocate temporary storage.");
            return NULL;
        }
        CFStringGetCharacters(originalString, CFRangeMake(0, length), buf);
        createdBuffer = true;
    }
    
    _CFStringsFileParseInfo stringsPInfo;
    stringsPInfo.begin = buf;
    stringsPInfo.end = buf+length;
    stringsPInfo.curr = buf;
    stringsPInfo.allocator = allocator;
    stringsPInfo.mutabilityOption = option;
    stringsPInfo.stringSet = CFSetCreateMutable(allocator, 0, &kCFTypeSetCallBacks);
    stringsPInfo.error = NULL;
    
    const UniChar *begin = stringsPInfo.curr;
    CFTypeRef result = NULL;
    Boolean foundChar = advanceToNonSpace(&stringsPInfo);
    if (!foundChar) {
        // A file consisting only of whitespace (or empty) is now defined to be an empty dictionary
        result = CFDictionaryCreateMutable(allocator, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
    } else {
        result = parsePlistObject(&stringsPInfo, true);
        if (result) {
            foundChar = advanceToNonSpace(&stringsPInfo);
            if (foundChar) {
                if (CFGetTypeID(result) != CFStringGetTypeID()) {
                    if (result) CFRelease(result);
                    result = NULL;
                    if (stringsPInfo.error) CFRelease(stringsPInfo.error);
                    stringsPInfo.error = __CFPropertyListCreateError(kCFPropertyListReadCorruptError, CFSTR("Junk after plist at line %d"), lineNumberStrings(&stringsPInfo));
                } else {
                    // Reset info and keep parsing
                    if (result) CFRelease(result);
                    if (stringsPInfo.error) CFRelease(stringsPInfo.error);
                    stringsPInfo.error = NULL;
                    
                    // Check for a strings file (looks like a dictionary without the opening/closing curly braces)
                    stringsPInfo.curr = begin;
                    result = parsePlistDictContent(&stringsPInfo);
                }
            }
        }
    }
    
    if (!result) {
        // Must return some kind of error if requested
        if (outError) {
            if (stringsPInfo.error) {
                // Transfer ownership
                *outError = stringsPInfo.error;
            } else {
                *outError = __CFPropertyListCreateError(kCFPropertyListReadCorruptError, CFSTR("Unknown error parsing property list around line %d"), lineNumberStrings(&stringsPInfo));
            }
        } else if (stringsPInfo.error) {
            // Caller doesn't want it, so we need to free it
            CFRelease(stringsPInfo.error);
        }
    }
    
    if (result && format) *format = kCFPropertyListOpenStepFormat;
    
    if (createdBuffer) CFAllocatorDeallocate(allocator, buf);
    CFRelease(stringsPInfo.stringSet);
    CFRelease(originalString);
    return result;
}