[libvirt] [PATCH] util/vshstring: fix the vir_strdup when src is NULL.

When src is NULL, vir_strdup will return 0 directly. This patch will set dest to NULL before vir_strdup return. Signed-off-by: yangdongsheng <yangds.fnst@cn.fujitsu.com> --- src/util/virstring.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index b244e6c..25b5d81 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -540,8 +540,10 @@ virStrdup(char **dest, const char *funcname, size_t linenr) { - if (!src) + if (!src) { + *dest = NULL; return 0; + } if (!(*dest = strdup(src))) { if (report) virReportOOMErrorFull(domcode, filename, funcname, linenr); -- 1.7.10.1

This bug will cause the dest get a unexpected value. Example: [root@yds-pc libvirt]# virsh Welcome to virsh, the virtualization interactive terminal. Type: 'help' for help with commands 'quit' to quit virsh # connect error: Failed to connect to the hypervisor error: internal error Unable to parse URI �N�*C Please someone give me a comment. Thanx~ On 05/28/2013 03:13 PM, yangdongsheng wrote:
When src is NULL, vir_strdup will return 0 directly. This patch will set dest to NULL before vir_strdup return.
Signed-off-by: yangdongsheng<yangds.fnst@cn.fujitsu.com> --- src/util/virstring.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/util/virstring.c b/src/util/virstring.c index b244e6c..25b5d81 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -540,8 +540,10 @@ virStrdup(char **dest, const char *funcname, size_t linenr) { - if (!src) + if (!src) { + *dest = NULL; return 0; + } if (!(*dest = strdup(src))) { if (report) virReportOOMErrorFull(domcode, filename, funcname, linenr);

On 05/28/2013 01:13 AM, yangdongsheng wrote:
When src is NULL, vir_strdup will return 0 directly. This patch will set dest to NULL before vir_strdup return.
Signed-off-by: yangdongsheng <yangds.fnst@cn.fujitsu.com> --- src/util/virstring.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
ACK, but VIR_STRNDUP has the same problem. I'm pushing this with an updated commit message (your followup mail that shows where it goes wrong if not set to NULL) and with both problems fixed.
diff --git a/src/util/virstring.c b/src/util/virstring.c index b244e6c..25b5d81 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -540,8 +540,10 @@ virStrdup(char **dest, const char *funcname, size_t linenr) { - if (!src) + if (!src) { + *dest = NULL; return 0; + } if (!(*dest = strdup(src))) { if (report) virReportOOMErrorFull(domcode, filename, funcname, linenr);
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (3)
-
Eric Blake
-
Yang Dongsheng
-
yangdongsheng