new interface

This commit is contained in:
Alex Groce 2018-12-31 13:06:01 -07:00
parent abba98ad2a
commit efb3c07314
3 changed files with 56 additions and 18 deletions

View File

@ -165,13 +165,13 @@ extern void *DeepState_ConcretizeData(void *begin, void *end);
/* Assign a symbolic C string of length `len` with only chars in allowed, /* Assign a symbolic C string of length `len` with only chars in allowed,
* if allowed is non-null */ * if allowed is non-null */
extern void DeepState_AssignCStr(char* str, size_t len, const char* allowed); extern void DeepState_AssignCStr_C(char* str, size_t len, const char* allowed);
/* Return a symbolic C string of length `len`. */ /* Return a symbolic C string of length `len`. */
extern char *DeepState_CStr(size_t len); extern char *DeepState_CStr_C(size_t len, const char* allowed);
/* Symbolize a C string */ /* Symbolize a C string */
void DeepState_SymbolizeCStr(char *begin); void DeepState_SymbolizeCStr_C(char *begin, const char* allowed);
/* Concretize a C string. Returns a pointer to the beginning of the /* Concretize a C string. Returns a pointer to the beginning of the
* concretized C string. */ * concretized C string. */

View File

@ -471,17 +471,32 @@ struct Comparer {
} }
}; };
/* Like DeepState_AssignCStr_C, but fills in a null allowed. */
inline static void DeepState_AssignCStr(char* str, size_t len,
const char* allowed = 0) {
DeepState_AssignCStr_C(str, len, allowed);
}
/* Like DeepState_AssignCStr, but Pumps through possible string sizes. */ /* Like DeepState_AssignCStr, but Pumps through possible string sizes. */
inline static void DeepState_AssignCStrMax(char* str, size_t max_len, inline static void DeepState_AssignCStrUpToLen(char* str, size_t max_len,
const char* allowed) { const char* allowed = 0) {
uint32_t size = DeepState_UIntInRange(0, max_len); uint32_t len = DeepState_UIntInRange(0, max_len);
DeepState_AssignCStr(str, Pump(size, max_len), allowed); DeepState_AssignCStr_C(str, Pump(len, max_len), allowed);
} }
/* Like DeepState_CStr_C, but fills in a null allowed. */
inline static char* DeepState_CStr(size_t len, char* allowed = 0) {
return DeepState_CStr_C(len, allowed);
}
/* Like DeepState_CStr, but Pumps through possible string sizes. */ /* Like DeepState_CStr, but Pumps through possible string sizes. */
inline static char* DeepState_CStrMax(size_t max_len) { inline static char* DeepState_CStrUpToLen(size_t max_len, char* allowed = 0) {
uint32_t size = DeepState_UIntInRange(0, max_len); uint32_t len = DeepState_UIntInRange(0, max_len);
return DeepState_CStr(Pump(size, max_len)); return DeepState_CStr_C(Pump(len, max_len), allowed);
}
inline static void DeepState_SymbolizeCStr_C(char *begin, char* allowed = 0) {
DeepState_SymbolizeCStr_C(begin, allowed);
} }
} // namespace deepstate } // namespace deepstate

View File

@ -176,22 +176,28 @@ void *DeepState_ConcretizeData(void *begin, void *end) {
} }
/* Assign a symbolic C string of length `len`. */ /* Assign a symbolic C string of length `len`. */
void DeepState_AssignCStr(char* str, size_t len, const char* allowed) { void DeepState_AssignCStr_C(char* str, size_t len, const char* allowed) {
if (SIZE_MAX == len) { if (SIZE_MAX == len) {
DeepState_Abandon("Can't create an SIZE_MAX-length string."); DeepState_Abandon("Can't create an SIZE_MAX-length string.");
} }
if (NULL == str) { if (NULL == str) {
DeepState_Abandon("Attempted to populate null pointer."); DeepState_Abandon("Attempted to populate null pointer.");
} }
uint32_t allowed_size = strlen(allowed); if (len) {
for (int i = 0; i < len; i++) { if (!allowed) {
str[i] = allowed[DeepState_UIntInRange(0, allowed_size)]; DeepState_SymbolizeData(str, &(str[len - 1]));
} else {
uint32_t allowed_size = strlen(allowed);
for (int i = 0; i < len; i++) {
str[i] = allowed[DeepState_UIntInRange(0, allowed_size)];
}
}
} }
str[len] = '\0'; str[len] = '\0';
} }
/* Return a symbolic C string of length `len`. */ /* Return a symbolic C string of length `len`. */
char *DeepState_CStr(size_t len) { char *DeepState_CStr_C(size_t len, const char* allowed) {
if (SIZE_MAX == len) { if (SIZE_MAX == len) {
DeepState_Abandon("Can't create an SIZE_MAX-length string."); DeepState_Abandon("Can't create an SIZE_MAX-length string.");
} }
@ -201,16 +207,33 @@ char *DeepState_CStr(size_t len) {
} }
DeepState_GeneratedStrings[DeepState_GeneratedStringsIndex++] = str; DeepState_GeneratedStrings[DeepState_GeneratedStringsIndex++] = str;
if (len) { if (len) {
DeepState_SymbolizeData(str, &(str[len - 1])); if (!allowed) {
DeepState_SymbolizeData(str, &(str[len - 1]));
} else {
uint32_t allowed_size = strlen(allowed);
for (int i = 0; i < len; i++) {
str[i] = allowed[DeepState_UIntInRange(0, allowed_size)];
}
}
} }
str[len] = '\0'; str[len] = '\0';
return str; return str;
} }
/* Symbolize a C string */ /* Symbolize a C string */
void DeepState_SymbolizeCStr(char *begin) { void DeepState_SymbolizeCStr_C(char *begin, const char* allowed) {
if (begin && begin[0]) { if (begin && begin[0]) {
DeepState_SymbolizeData(begin, begin + strlen(begin)); if (!allowed) {
DeepState_SymbolizeData(begin, begin + strlen(begin));
} else {
uint32_t allowed_size = strlen(allowed);
uint8_t *bytes = (uint8_t *) begin;
uintptr_t begin_addr = (uintptr_t) begin;
uintptr_t end_addr = (uintptr_t) (begin + strlen(begin));
for (uintptr_t i = 0, max_i = (end_addr - begin_addr); i < max_i; ++i) {
bytes[i] = allowed[DeepState_UIntInRange(0, allowed_size)];
}
}
} }
} }