Index: branches/ErmaC/Enoch/i386/libsaio/stringTable.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/stringTable.c (revision 2688) +++ branches/ErmaC/Enoch/i386/libsaio/stringTable.c (revision 2689) @@ -102,7 +102,7 @@ tab = (char *)table; buf = (char *)malloc(len + 3); - sprintf(buf, "\"%s\"", key); + snprintf(buf, len + 3,"\"%s\"", key); len = strlen(buf); while(*tab) { @@ -156,6 +156,10 @@ } bufsize = end - begin + 1; newstr = malloc(bufsize); + if (!newstr) + { + return 0; + } strlcpy(newstr, begin, bufsize); *list = end; *size = newsize; @@ -175,8 +179,11 @@ if (*table == '\\') { table += 2; ret += 1 + (compress ? 0 : 1); - } else { - if (*table == '\"') { + } + else + { + if (*table == '\"') + { return ret; } ret++; @@ -224,8 +231,13 @@ char *newstr, *p; int size; - if (getValueForConfigTableKey(config, key, &val, &size)) { + if (getValueForConfigTableKey(config, key, &val, &size)) + { newstr = (char *)malloc(size+1); + if (!newstr) + { + return 0; + } for (p = newstr; size; size--, p++, val++) { if ((*p = *val) == '\\') { switch (*++val) { @@ -263,6 +275,10 @@ if (getValueForKey(key, &val, &size, config) && size) { newstr = (char *)malloc(size + 1); + if (!newstr) + { + return 0; + } strlcpy(newstr, val, size + 1); return newstr; } else { @@ -302,7 +318,8 @@ while (*line) { /* look for keyword or argument */ - while (isspace(*line)) { + while (isspace(*line)) + { line++; } @@ -315,12 +332,13 @@ value = line; value_len = 0; } - if ((strlen(match) == key_len) && strncmp(match, key, key_len) == 0) { + if ((strlen(match) == key_len) && strncmp(match, key, key_len) == 0) + { // create a new string char* newstr = malloc(value_len + 1); strncpy(newstr, value, value_len); newstr[value_len] = 0; - + *matchval = newstr; *len = value_len; retval = true; @@ -374,23 +392,29 @@ int size, sum; bool negative = false; - if (getValueForKey(key, &val, &size, config)) { - if (size) { - if (*val == '-') { + if (getValueForKey(key, &val, &size, config)) + { + if (size) + { + if (*val == '-') + { negative = true; val++; size--; } - for (sum = 0; size > 0; size--) { - if (*val < '0' || *val > '9') { + for (sum = 0; size > 0; size--) + { + if (*val < '0' || *val > '9') + { return false; } sum = (sum * 10) + (*val++ - '0'); } - if (negative) { + if (negative) + { sum = -sum; } *value = sum; @@ -399,7 +423,6 @@ } return false; } - /* * */ @@ -414,38 +437,48 @@ bool negative = false; bool percentage = false; - if (getValueForKey(key, &val, &size, config)) { - if ( size ) { - if (*val == '-') { + if (getValueForKey(key, &val, &size, config)) + { + if ( size ) + { + if (*val == '-') + { negative = true; val++; size--; } - if (val[size-1] == '%') { + if (val[size-1] == '%') + { percentage = true; size--; } // convert string to integer - for (sum = 0; size > 0; size--) { - if (*val < '0' || *val > '9') { + for (sum = 0; size > 0; size--) + { + if (*val < '0' || *val > '9') + { return false; } sum = (sum * 10) + (*val++ - '0'); } - if (percentage) { + if (percentage) + { sum = ( dimension_max * sum ) / 100; } // calculate offset from opposite origin - if (negative) { + if (negative) + { sum = ( ( dimension_max - object_size ) - sum ); } - } else { + } + else + { // null value calculate center sum = ( dimension_max - object_size ) / 2; @@ -486,7 +519,8 @@ int overrideSize; bool override, ret; - if (getValueForBootKey(bootArgs->CommandLine, key, val, size)) { + if (getValueForBootKey(bootArgs->CommandLine, key, val, size)) + { return true; } @@ -496,21 +530,26 @@ // and prefer its values with the exceptions for // "Kernel"="mach_kernel" and "Kernel Flags"="". - if (config->canOverride) { - if (getValueForConfigTableKey(&bootInfo->chameleonConfig, key, &overrideVal, &overrideSize)) { + if (config->canOverride) + { + if (getValueForConfigTableKey(&bootInfo->chameleonConfig, key, &overrideVal, &overrideSize)) + { override = true; // NOTE: Values are defined by apple as being in com.apple.Boot.plist // kHelperRootUUIDKey, kKernelArchKey, kMKextCacheKey, kKernelCacheKey, kKernelNameKey, kKernelFlagsKey - if (ret && (strcmp(key, kKernelNameKey) == 0) && (overrideSize == 0)) { + if (ret && (strcmp(key, kKernelNameKey) == 0) && (overrideSize == 0)) + { override = false; } - if (ret && (strcmp(key, kKernelFlagsKey) == 0) && (overrideSize == 0)) { + if (ret && (strcmp(key, kKernelFlagsKey) == 0) && (overrideSize == 0)) + { override = false; } - if (override) { + if (override) + { *val = overrideVal; *size = overrideSize; ret = true; @@ -527,15 +566,18 @@ { char *p2 = p1, tmp; - while (*p1 != '\0') { - while (*p2 != '\0' && *p2 != '\n') { + while (*p1 != '\0') + { + while (*p2 != '\0' && *p2 != '\n') + { p2++; } tmp = *p2; *p2 = '\0'; printf("%s\n", p1); *p2 = tmp; - if (tmp == '\0') { + if (tmp == '\0') + { break; } p1 = ++p2; @@ -555,25 +597,35 @@ int ParseXMLFile( char *buffer, TagPtr *dict ) { long length, pos; - TagPtr tag; + TagPtr tag = 0; pos = 0; char *configBuffer; + + length = strlen(buffer) + 1; configBuffer = malloc(strlen(buffer)+1); - strcpy(configBuffer, buffer); + if (!configBuffer) + { + return -1; + } + strlcpy(configBuffer, buffer, length ); - while (1) { + while (1) + { length = XMLParseNextTag(configBuffer + pos, &tag); - if (length == -1) { + if (length == -1) + { break; } pos += length; - if (tag == 0) { + if (tag == 0) + { continue; } - if (tag->type == kTagTypeDict) { + if (tag->type == kTagTypeDict) + { break; } @@ -738,29 +790,110 @@ */ int loadHelperConfig(config_file_t *config) { + int rfd, pfd, sfd, count, ret=-1, fixedsize; + char *dirspec[] = { "/com.apple.boot.P/Library/Preferences/SystemConfiguration/com.apple.Boot.plist", "/com.apple.boot.R/Library/Preferences/SystemConfiguration/com.apple.Boot.plist", "/com.apple.boot.S/Library/Preferences/SystemConfiguration/com.apple.Boot.plist" }; - int i, fd, count, ret=-1; + // This is a simple rock - paper scissors algo. R beats S, P beats R, S beats P + // If all three, S is used for now. This should be changed to something else (say, timestamp?) - for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) + pfd = open(dirspec[0], 0); + if(pfd >= 0) // com.apple.boot.P exists { - if ((fd = open(dirspec[i], 0)) >= 0) + + sfd = open(dirspec[2], 0); // com.apple.boot.S takes precidence if it also exists + if(sfd >= 0) { - // read file - count = read(fd, config->plist, IO_CONFIG_DATA_SIZE); - close(fd); - + // Use sfd + fixedsize = MIN(file_size(sfd),IO_CONFIG_DATA_SIZE); + count = read(sfd, config->plist, fixedsize); + close(sfd); + close(pfd); + if (count != fixedsize) return -1; + // build xml dictionary ParseXMLFile(config->plist, &config->dictionary); - sysConfigValid = true; + sysConfigValid = true; ret=0; - break; + } + else + { + // used pfd + fixedsize = MIN(file_size(pfd),IO_CONFIG_DATA_SIZE); + count = read(pfd, config->plist, fixedsize); + close(pfd); + if (count != fixedsize) return -1; + + // build xml dictionary + ParseXMLFile(config->plist, &config->dictionary); + sysConfigValid = true; + ret = 0; + } + } + else + { + rfd = open(dirspec[1], 0); // com.apple.boot.R exists + if(rfd >= 0) + { + pfd = open(dirspec[2], 0); // com.apple.boot.P takes recidence if it exists + if(pfd >= 0) + { + // use sfd + fixedsize = MIN(file_size(pfd),IO_CONFIG_DATA_SIZE); + count = read(pfd, config->plist, fixedsize); + close(pfd); + close(rfd); + if (count != fixedsize) return -1; + + // build xml dictionary + ParseXMLFile(config->plist, &config->dictionary); + sysConfigValid = true; + ret = 0; + + } + else + { + // use rfd + fixedsize = MIN(file_size(rfd),IO_CONFIG_DATA_SIZE); + count = read(rfd, config->plist, fixedsize); + close(rfd); + if (count != fixedsize) return -1; + + // build xml dictionary + ParseXMLFile(config->plist, &config->dictionary); + sysConfigValid = true; + ret = 0; + + } + + } + else + { + sfd = open(dirspec[2], 0); // com.apple.boot.S exists, but nothing else does + if(sfd >= 0) + { + // use sfd + fixedsize = MIN(file_size(sfd),IO_CONFIG_DATA_SIZE); + count = read(sfd, config->plist, fixedsize); + close(sfd); + if (count != fixedsize) return -1; + + // build xml dictionary + ParseXMLFile(config->plist, &config->dictionary); + sysConfigValid = true; + ret = 0; + + } + } + + } + return ret; } Index: branches/ErmaC/Enoch/CHANGES =================================================================== --- branches/ErmaC/Enoch/CHANGES (revision 2688) +++ branches/ErmaC/Enoch/CHANGES (revision 2689) @@ -1,3 +1,4 @@ +- cparm : Rock - Paper - Scissors algo - Bronya : Improve support for AMD CPU. - Bungo : Added "machine-signature" - Zenith432 : Protect timing code in scan_cpu() from interrupts, use bios for sleep()