Blob Blame History Raw
From c20c666cc04fd0a8258e318855bdac0a0b90ad7f Mon Sep 17 00:00:00 2001
From: "Daniel P. Berrange" <berrange@redhat.com>
Date: Fri, 17 Jul 2015 17:19:10 +0100
Subject: [PATCH] Ensure typed param key is null terminated

The strncpy() function may leave the result unterminated if
there is no \0 byte in the original string. The coverity
checker thinks vir_typed_param_add_string_list_from_hv()
suffers from this flaw. It is wrong, because all callers
pass a sane key value, but fix it anyway to keep coverity
quiet.

(cherry picked from commit 4447d56dfb5d94188a38854b0d643e741e0df5e8)
---
 Virt.xs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Virt.xs b/Virt.xs
index 8f725e6..6613fb7 100644
--- a/Virt.xs
+++ b/Virt.xs
@@ -297,6 +297,7 @@ vir_typed_param_add_string_list_from_hv(HV *newparams,
 
       strncpy(localparams[*nparams + i].field, key,
 	      VIR_TYPED_PARAM_FIELD_LENGTH);
+      localparams[*nparams + i].field[VIR_TYPED_PARAM_FIELD_LENGTH - 1] = '\0';
 
       localparams[*nparams + i].type = VIR_TYPED_PARAM_STRING;
       localparams[*nparams + i].value.s = ptr;