avoid reading uninitialized memory in test program

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

 



valgrind complained about the printf in conftest.c.
Here's the fix:

	* src/conf.c (__virConfWriteMem): Fix typos in comment.
	* tests/conftest.c (main): Use fwrite, not printf, since the
	result buffer is not NUL-terminated.

===================================================================
RCS file: /data/cvs/libvirt/src/conf.c,v
retrieving revision 1.11
diff -u -p -r1.11 conf.c
--- src/conf.c	4 Jul 2007 09:16:23 -0000	1.11
+++ src/conf.c	17 Oct 2007 11:31:54 -0000
@@ -1,7 +1,7 @@
 /**
  * conf.c: parser for a subset of the Python encoded Xen configuration files
  *
- * Copyright (C) 2006 Red Hat, Inc.
+ * Copyright (C) 2006, 2007 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
@@ -916,7 +916,7 @@ error:
 /**
  * __virConfWriteMem:
  * @memory: pointer to the memory to store the config file
- * @len: pointer to the lenght in byte of the store, on output the size
+ * @len: pointer to the length in bytes of the store, on output the size
  * @conf: the conf
  *
  * Writes a configuration file back to a memory area. @len is an IN/OUT
===================================================================
RCS file: /data/cvs/libvirt/tests/conftest.c,v
retrieving revision 1.1
diff -u -p -r1.1 conftest.c
--- tests/conftest.c	29 Aug 2006 22:27:07 -0000	1.1
+++ tests/conftest.c	17 Oct 2007 11:31:54 -0000
@@ -24,7 +24,10 @@ int main(int argc, char **argv) {
         fprintf(stderr, "Failed to serialize %s back\n", argv[1]);
 	exit(3);
     }
-    printf("%s", buffer);
     virConfFree(conf);
+    if (fwrite(buffer, len, 1, stdout) != len) {
+	fprintf(stderr, "Write failed\n");
+	exit(1);
+    }
     exit(0);
 }

--
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]