Re: [PATCH 4/5] phyp: Fix too small buffer allocation in phypAttachDevice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2011/4/11 Daniel Veillard <veillard@xxxxxxxxxx>:
> 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++;
         }
     }

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]