Skip to contentSkip to conversation

libxl: fix the bug which will cause heap to break down

PATCH In review Liliang 2 participants 3 messages Jun 27, 2014 – Jun 30, 2014

lore
Share & tools
lore

Liliang

author
#0 lore raw

PATCH v2 1/1 libxl: fix the bug which will cause heap to break down

From: Li Liang <[email protected]>

If the JSON message contains more bytes than QMP_RECEIVE_BUFFER_SIZE, this bug will break down the heap, that leads to core dump. One more byte should be allocated to contain the appended null character.

---
 tools/libxl/libxl_qmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_qmp.c +1 -1
index 8433e42..5cc56b1 100644
@@ -456,7 +456,7 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp)
             if (incomplete) {
                 size_t current_pos = s - incomplete;
                 incomplete = libxl__realloc(gc, incomplete,
-                                            incomplete_size + rd);
+                                            incomplete_size + rd + 1);
                 strncat(incomplete + incomplete_size, qmp->buffer, rd);
                 s = incomplete + current_pos;
                 incomplete_size += rd;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 7 lines · Liliang

From: Li Liang <[email protected]>

If the JSON message contains more bytes than QMP_RECEIVE_BUFFER_SIZE, this bug will break down the heap, that leads to core dump. One more byte should be allocated to contain the appended null character.

Does this differ from v1 in some way? I can't spot it. I'm not sure if maybe you meant to send with a different but accidentally resent v1 again, so I won't apply just yet.

I take the +1 is for the NULL terminator?

Also, please CC the maintainer. You can use ./scripts/get_maintainers.pl to guide you on who that is for a given patch.

Quoted 17 lines
---
 tools/libxl/libxl_qmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_qmp.c +1 -1
index 8433e42..5cc56b1 100644
@@ -456,7 +456,7 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp)
             if (incomplete) {
                 size_t current_pos = s - incomplete;
                 incomplete = libxl__realloc(gc, incomplete,
-                                            incomplete_size + rd);
+                                            incomplete_size + rd + 1);
                 strncat(incomplete + incomplete_size, qmp->buffer, rd);
                 s = incomplete + current_pos;
                 incomplete_size += rd;
#2 lore raw

Yes, they are the same. I resend it because the original one is not based on the latest code base. I will redo it as your command.

-----Original Message-----
From: Ian Campbell [mailto:[email protected]]
Sent: Friday, June 27, 2014 8:01 PM
To: Li, LiangX Z
Cc: [email protected]
Subject: Re: [PATCH v2] libxl: fix the bug which will cause heap to break down

Quoted 7 lines · Liliang

From: Li Liang <[email protected]>

If the JSON message contains more bytes than QMP_RECEIVE_BUFFER_SIZE, this bug will break down the heap, that leads to core dump. One more byte should be allocated to contain the appended null character.

Does this differ from v1 in some way? I can't spot it. I'm not sure if maybe you meant to send with a different but accidentally resent v1 again, so I won't apply just yet.

I take the +1 is for the NULL terminator?

Also, please CC the maintainer. You can use ./scripts/get_maintainers.pl to guide you on who that is for a given patch.

Quoted 18 lines
---
 tools/libxl/libxl_qmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_qmp.c index renamed from tools/libxl/libxl_qmp.c +0 -0

8433e42..5cc56b1 100644

tools/libxl/libxl_qmp.c +2 -1
@@ -456,7 +456,7 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp)
             if (incomplete) {
                 size_t current_pos = s - incomplete;
                 incomplete = libxl__realloc(gc, incomplete,
-                                            incomplete_size + rd);
+                                            incomplete_size + rd + 
+ 1);
                 strncat(incomplete + incomplete_size, qmp->buffer, rd);
                 s = incomplete + current_pos;
                 incomplete_size += rd;