Skip to contentSkip to conversation

libxl: qmp: ensure qmp read buffer is NULL terminated

PATCH In review Ian Campbell 2 participants 3 messages Feb 17, 2016 – Mar 1, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: qmp: ensure qmp read buffer is NULL terminated

Coverity rightly points out that qmp->buffer may not be NULL terminated when passed to strncat.

Make the actual buffer a byte bigger than QMP_RECEIVE_BUFFER_SIZE and always append a NULL byte.

I suspect that in practice we have not yet seen QMP messages approaching the buffer size (4K).

Compile tested only.

CID: 1055989

---
 tools/libxl/libxl_qmp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libxl/libxl_qmp.c +2 -1
index 714038b..c45702e 100644
@@ -67,7 +67,7 @@ struct libxl__qmp_handler {
     /* wait_for_id will be used by the synchronous send function */
     int wait_for_id;
 
-    char buffer[QMP_RECEIVE_BUFFER_SIZE];
+    char buffer[QMP_RECEIVE_BUFFER_SIZE + 1];
     libxl__yajl_ctx *yajl_ctx;
 
     libxl_ctx *ctx;
@@ -457,6 +457,7 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp)
             LOGE(ERROR, "Socket read error");
             return rd;
         }
+        qmp->buffer[rd] = '\0';
 
         DEBUG_REPORT_RECEIVED(qmp->buffer, rd);
 
Signature · 1 line
2.1.4
#1 lore raw
Quoted 6 lines · Ian Campbell

Coverity rightly points out that qmp->buffer may not be NULL terminated when passed to strncat.

Make the actual buffer a byte bigger than QMP_RECEIVE_BUFFER_SIZE and always append a NULL byte.

Quoted 8 lines

I suspect that in practice we have not yet seen QMP messages approaching the buffer size (4K).

Compile tested only.

CID: 1055989

ping.

Quoted 23 lines

---
 tools/libxl/libxl_qmp.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
tools/libxl/libxl_qmp.c +0 -0
index 714038b..c45702e 100644
@@ -67,7 +67,7 @@ struct libxl__qmp_handler {
      /* wait_for_id will be used by the synchronous send function */
      int wait_for_id;


-    char buffer[QMP_RECEIVE_BUFFER_SIZE];
+    char buffer[QMP_RECEIVE_BUFFER_SIZE + 1];
     libxl__yajl_ctx *yajl_ctx;

     libxl_ctx *ctx;

tools/libxl/libxl_qmp.c +1 -0
@@ -457,6 +457,7 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler
 *qmp)
              LOGE(ERROR, "Socket read error");
              return rd;
          }
+        qmp->buffer[rd] = '\0';
Quoted 3 lines


         DEBUG_REPORT_RECEIVED(qmp->buffer, rd);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v1 1/1
#2 lore raw
In reply to Ian Campbell

Ian Campbell writes ("[PATCH] libxl: qmp: ensure qmp read buffer is NULL terminated"):

Quoted 6 lines

Coverity rightly points out that qmp->buffer may not be NULL terminated when passed to strncat.

Make the actual buffer a byte bigger than QMP_RECEIVE_BUFFER_SIZE and always append a NULL byte.

Quoted 8 lines

I suspect that in practice we have not yet seen QMP messages approaching the buffer size (4K).

Compile tested only.

CID: 1055989

and queued

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel