[syslinux:master] hdt: Fixing memory corruption

syslinux-bot for Erwan Velu erwanaliasr1 at gmail.com
Mon Apr 25 15:28:15 PDT 2011


Commit-ID:  baac23fcbb985b10ad2c06dd33d3e07835d7f0b5
Gitweb:     http://syslinux.zytor.com/commit/baac23fcbb985b10ad2c06dd33d3e07835d7f0b5
Author:     Erwan Velu <erwanaliasr1 at gmail.com>
AuthorDate: Tue, 22 Mar 2011 23:02:55 +0100
Committer:  Erwan Velu <erwanaliasr1 at gmail.com>
CommitDate: Tue, 22 Mar 2011 23:02:55 +0100

hdt: Fixing memory corruption

When flusing the output, we need to reset also len & size.


---
 com32/hdt/hdt-dump.c |   15 ++++++---------
 com32/hdt/hdt-dump.h |    3 ++-
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/com32/hdt/hdt-dump.c b/com32/hdt/hdt-dump.c
index 324fd81..429902d 100644
--- a/com32/hdt/hdt-dump.c
+++ b/com32/hdt/hdt-dump.c
@@ -59,11 +59,6 @@ void compute_filename(struct s_hardware *hardware, char *filename, int size) {
 
 }
 
-void print_and_flush(ZZJSON_CONFIG *config, ZZJSON **item) {
-	zzjson_print(config, *item);
-        zzjson_free(config, *item);
-}
-
 int dumpprintf(FILE *p, const char *format, ...) {
    va_list ap;
    int rv;
@@ -76,12 +71,15 @@ int dumpprintf(FILE *p, const char *format, ...) {
 }
 
 void flush (char *filename, ZZJSON_CONFIG *config, ZZJSON ** item) { 
-   print_and_flush(config,item);
+   zzjson_print(config, *item);
    cpio_writefile(upload,filename,p_buf.buf,p_buf.len);
-   if (p_buf.buf) { 
+   if ((p_buf.buf) && (p_buf.size > 0)){ 
       memset(p_buf.buf,0,p_buf.size);
       free(p_buf.buf); 
+      p_buf.size=0;
+      p_buf.len=0;
    }
+   zzjson_free(config, *item);
 }
 
 /**
@@ -99,8 +97,6 @@ void dump(struct s_hardware *hardware)
 		(int(*)(int,void*)) fputc 
     };
 
-    detect_hardware(hardware);
-
     /* By now, we only support TFTP reporting */
     upload=&upload_tftp;
     upload->name="tftp";
@@ -120,6 +116,7 @@ void dump(struct s_hardware *hardware)
 
     dump_cpu(hardware, &config, &json);
     dump_pxe(hardware, &config, &json);
+    dump_syslinux(hardware, &config, &json);
 
     /* We close & flush the file to send */
     cpio_close(upload);
diff --git a/com32/hdt/hdt-dump.h b/com32/hdt/hdt-dump.h
index 933d543..0f1f817 100644
--- a/com32/hdt/hdt-dump.h
+++ b/com32/hdt/hdt-dump.h
@@ -39,7 +39,7 @@
 #define add_bool_true(name) *item = zzjson_object_append(config, *item, name, zzjson_create_true(config))
 #define add_bool_false(name) *item = zzjson_object_append(config, *item, name, zzjson_create_false(config))
 #define add_hi(value) add_i(#value,hardware->value)
-#define add_hs(value) add_s(#value,hardware->value)
+#define add_hs(value) add_s(#value,(char *)hardware->value)
 #define add_b(name,value) if (value==true) {add_bool_true((char *)name);} else {add_bool_false((char *)name);}
 
 extern struct print_buf p_buf;
@@ -50,3 +50,4 @@ void flush (char *filename, ZZJSON_CONFIG *config, ZZJSON ** item);
 
 void dump_cpu(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item);
 void dump_pxe(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item);
+void dump_syslinux(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item);



More information about the Syslinux-commits mailing list