
2011/4/11 Daniel Veillard <veillard@redhat.com>:
On Sat, Apr 09, 2011 at 11:59:10AM +0200, Matthias Bolte wrote:
sizeof(domain->name) is the wrong thing. Instead of using strdup here rewrite escape_specialcharacters to allocate the buffer itself.
Add a contains_specialcharacters to be used in phypOpen, as phypOpen is not interested in the escaped version. --- src/phyp/phyp_driver.c | 90 ++++++++++++++++++++++++++++++++--------------- 1 files changed, 61 insertions(+), 29 deletions(-)
ACK, we just need to make sure contains_specialcharacters() and escape_specialcharacters() don't diverge on the charater set. Maybe add a comment in escape_specialcharacters() to this effect.
Daniel
I just moved the character set to a define, like this and pushed the result. diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 2eb8317..3862c9c 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -894,6 +894,12 @@ phypUUIDTable_Free(uuid_tablePtr uuid_table) VIR_FREE(uuid_table); } +#define SPECIALCHARACTER_CASES \ + case '&': case ';': case '`': case '@': case '"': case '|': case '*': \ + case '?': case '~': case '<': case '>': case '^': case '(': case ')': \ + case '[': case ']': case '{': case '}': case '$': case '%': case '#': \ + case '\\': case '\n': case '\r': case '\t': + static bool contains_specialcharacters(const char *src) { @@ -905,32 +911,10 @@ contains_specialcharacters(const char *src) for (i = 0; i < len; i++) { switch (src[i]) { - case '&': - case ';': - case '`': - case '@': - case '"': - case '|': - case '*': - case '?': - case '~': - case '<': - case '>': - case '^': - case '(': - case ')': - case '[': - case ']': - case '{': - case '}': - case '$': - case '%': - case '#': - case '\\': - case '\n': - case '\r': - case '\t': - return true; + SPECIALCHARACTER_CASES + return true; + default: + continue; } } @@ -954,35 +938,11 @@ escape_specialcharacters(const char *src) for (i = 0; i < len; i++) { switch (src[i]) { - case '&': - case ';': - case '`': - case '@': - case '"': - case '|': - case '*': - case '?': - case '~': - case '<': - case '>': - case '^': - case '(': - case ')': - case '[': - case ']': - case '{': - case '}': - case '$': - case '%': - case '#': - case '\\': - case '\n': - case '\r': - case '\t': - continue; - default: - dst[j] = src[i]; - j++; + SPECIALCHARACTER_CASES + continue; + default: + dst[j] = src[i]; + j++; } }