From: Jan-Benedict G. <jb...@us...> - 2007-06-05 22:09:14
|
Update of /cvsroot/linux-vax/usr/visualize_asm In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9395 Modified Files: Makefile address.c address.h graphic.c graphic.h graphic_dot.c parse.h parse_backend.c parse_disassembly.c parse_i386.c parse_vax.c regexp_helper.c regexp_helper.h Log Message: * Touch-ups all over the place. * Specifically fix a use-after-free bug in regexp_helper.c Index: graphic_dot.c =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/graphic_dot.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- graphic_dot.c 14 Mar 2005 08:54:37 -0000 1.2 +++ graphic_dot.c 5 Jun 2007 22:09:06 -0000 1.3 @@ -10,8 +10,8 @@ #define CLUSTER "cluster: " -static unsigned char * -alloc_sprintf_valist (unsigned char *format, va_list args) +static char * +alloc_sprintf_valist (char *format, va_list args) { char buf[1]; char *real_buf; @@ -28,9 +28,9 @@ } static int -dot_set_last_anchor (unsigned char *format, ...) +dot_set_last_anchor (char *format, ...) { - unsigned char *buf; + char *buf; va_list args; if (!format) { @@ -56,10 +56,10 @@ return -1; } -static unsigned char * +static char * dot_section_name (void) { - unsigned char *section_name; + char *section_name; section_name = get_section_name (); if (!section_name) @@ -103,7 +103,7 @@ } static int -dot_start_output (unsigned char *filename) +dot_start_output (char *filename) { /* XXX escape filename */ printf ("digraph \"%s\" {\n", filename); @@ -123,7 +123,7 @@ } static int -dot_start_section (unsigned char *name) +dot_start_section (char *name) { dot_close_section_block (); @@ -136,7 +136,7 @@ } static int -dot_start_function (unsigned char *name, uint64_t address) +dot_start_function (char *name, uint64_t address) { dot_close_function_block (); @@ -150,7 +150,7 @@ } static int -dot_push_normal_code (unsigned char *code, uint64_t address) +dot_push_normal_code (char *code, uint64_t address) { if (last_anchor) printf ("\t\t\t\"%s\" -> \"%s:0x%016llx\";\n", last_anchor, @@ -163,7 +163,7 @@ } static int -dot_push_jump (unsigned char *code, uint64_t address, uint64_t jump_address) +dot_push_jump (char *code, uint64_t address, uint64_t jump_address) { dot_close_code_block (); @@ -184,7 +184,7 @@ } static int -dot_push_cond_jump (unsigned char *code, uint64_t address, uint64_t jump_address) +dot_push_cond_jump (char *code, uint64_t address, uint64_t jump_address) { dot_close_code_block (); @@ -205,7 +205,7 @@ } static int -dot_push_ret (unsigned char *code, uint64_t address) +dot_push_ret (char *code, uint64_t address) { if (last_anchor) printf ("\t\t\t\"%s\" -> \"%s:0x%016llx\";\n", last_anchor, @@ -227,4 +227,3 @@ .push_cond_jump = &dot_push_cond_jump, .push_ret = &dot_push_ret, }; - Index: graphic.h =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/graphic.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- graphic.h 14 Mar 2005 08:54:37 -0000 1.2 +++ graphic.h 5 Jun 2007 22:09:06 -0000 1.3 @@ -4,27 +4,27 @@ #include <stdint.h> struct graphic_implementation { - int (*start_output) (unsigned char *filename); + int (*start_output) (char *filename); int (*finish_output) (void); - int (*start_section) (unsigned char *name); - int (*start_function) (unsigned char *name, uint64_t address); - int (*push_normal_code) (unsigned char *code, uint64_t address); - int (*push_jump) (unsigned char *code, uint64_t address, uint64_t jump_address); - int (*push_cond_jump) (unsigned char *code, uint64_t address, uint64_t jump_address); - int (*push_ret) (unsigned char *code, uint64_t address); + int (*start_section) (char *name); + int (*start_function) (char *name, uint64_t address); + int (*push_normal_code) (char *code, uint64_t address); + int (*push_jump) (char *code, uint64_t address, uint64_t jump_address); + int (*push_cond_jump) (char *code, uint64_t address, uint64_t jump_address); + int (*push_ret) (char *code, uint64_t address); }; -extern int graphic_init (unsigned char *name); -extern int graphic_start_output (unsigned char *filename); +extern int graphic_init (char *name); +extern int graphic_start_output (char *filename); extern int graphic_finish_output (void); -extern int graphic_start_section (unsigned char *name); -extern int graphic_start_function (unsigned char *name, uint64_t address); -extern int graphic_push_normal_code (unsigned char *code, uint64_t address); -extern int graphic_push_jump (unsigned char *code, uint64_t address, uint64_t jump_address); -extern int graphic_push_cond_jump (unsigned char *code, uint64_t address, uint64_t jump_address); -extern int graphic_push_ret (unsigned char *code, uint64_t address); +extern int graphic_start_section (char *name); +extern int graphic_start_function (char *name, uint64_t address); +extern int graphic_push_normal_code (char *code, uint64_t address); +extern int graphic_push_jump (char *code, uint64_t address, uint64_t jump_address); +extern int graphic_push_cond_jump (char *code, uint64_t address, uint64_t jump_address); +extern int graphic_push_ret (char *code, uint64_t address); -extern unsigned char *get_section_name (void); +extern char *get_section_name (void); #endif /* GRAPHICS_H */ Index: Makefile =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/Makefile,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Makefile 11 Mar 2005 21:29:34 -0000 1.1 +++ Makefile 5 Jun 2007 22:09:05 -0000 1.2 @@ -1,7 +1,7 @@ #!/usr/bin/make -f CC = gcc -CFLAGS = -g -Wall -Werror -D_GNU_SOURCE +CFLAGS = -g -Wall -Werror -D_GNU_SOURCE -std=gnu99 all: $(CC) $(CFLAGS) -c -o parse_vax.o parse_vax.c @@ -21,6 +21,11 @@ regexp_helper.o \ parse_backend.o +te: all + ./disassemble vax te.dis > xx 2> yy + dot -Tps < xx > xx.ps + poster -mA4 -p6x4A4 < xx.ps > xxx.ps + vax: all ./disassemble vax vax.dis > xx 2> yy && dot -Tps < xx > xx.ps && poster -mA4 -p6x4A4 < xx.ps > xxx.ps @@ -29,4 +34,3 @@ clean: -rm -f *.o core disassemble xx yy xx.* yy.* xxx.* - Index: parse_disassembly.c =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/parse_disassembly.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- parse_disassembly.c 11 Mar 2005 21:29:34 -0000 1.1 +++ parse_disassembly.c 5 Jun 2007 22:09:06 -0000 1.2 @@ -7,7 +7,7 @@ #include "graphic.h" static void -kill_newline (unsigned char *line) +kill_newline (char *line) { int i = 0; @@ -25,8 +25,8 @@ { int ret; char line[1000]; - unsigned char *parser; - unsigned char *filename = NULL; + char *parser; + char *filename = NULL; FILE *stream; struct arch_parser_table *table; @@ -66,7 +66,7 @@ return -1; } - graphic_start_output (filename? filename: (unsigned char *) "<stdin>"); + graphic_start_output (filename? filename: "<stdin>"); while (fgets (line, sizeof (line), stream)) { kill_newline (line); @@ -81,6 +81,5 @@ graphic_finish_output (); - return EXIT_SUCCESS; + return 0; } - Index: parse_i386.c =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/parse_i386.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- parse_i386.c 11 Mar 2005 21:29:34 -0000 1.1 +++ parse_i386.c 5 Jun 2007 22:09:06 -0000 1.2 @@ -50,4 +50,3 @@ }, { }, }; - Index: graphic.c =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/graphic.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- graphic.c 11 Mar 2005 21:29:34 -0000 1.1 +++ graphic.c 5 Jun 2007 22:09:05 -0000 1.2 @@ -6,10 +6,10 @@ extern struct graphic_implementation graphic_dot; static struct graphic_implementation *graphic = NULL; -static unsigned char *section_name = NULL; +static char *section_name = NULL; int -graphic_init (unsigned char *name) +graphic_init (char *name) { if (strcmp (name, "dot") == 0) graphic = &graphic_dot; @@ -23,7 +23,7 @@ } int -graphic_start_output (unsigned char *filename) +graphic_start_output (char *filename) { if (graphic && graphic->start_output) return (graphic->start_output) (filename); @@ -41,7 +41,7 @@ } int -graphic_start_section (unsigned char *name) +graphic_start_section (char *name) { if (section_name) { free (section_name); @@ -56,7 +56,7 @@ } int -graphic_start_function (unsigned char *name, uint64_t address) +graphic_start_function (char *name, uint64_t address) { if (graphic && graphic->start_function) return (graphic->start_function) (name, address); @@ -65,7 +65,7 @@ } int -graphic_push_normal_code (unsigned char *code, uint64_t address) +graphic_push_normal_code (char *code, uint64_t address) { if (graphic && graphic->push_normal_code) return (graphic->push_normal_code) (code, address); @@ -74,7 +74,7 @@ } int -graphic_push_jump (unsigned char *code, uint64_t address, uint64_t jump_address) +graphic_push_jump (char *code, uint64_t address, uint64_t jump_address) { if (graphic && graphic->push_jump) return (graphic->push_jump) (code, address, jump_address); @@ -83,7 +83,7 @@ } int -graphic_push_cond_jump (unsigned char *code, uint64_t address, uint64_t jump_address) +graphic_push_cond_jump (char *code, uint64_t address, uint64_t jump_address) { if (graphic && graphic->push_cond_jump) return (graphic->push_cond_jump) (code, address, jump_address); @@ -92,7 +92,7 @@ } int -graphic_push_ret (unsigned char *code, uint64_t address) +graphic_push_ret (char *code, uint64_t address) { if (graphic && graphic->push_ret) return (graphic->push_ret) (code, address); @@ -100,9 +100,8 @@ return -1; } -unsigned char * +char * get_section_name (void) { return section_name; } - Index: address.c =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/address.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- address.c 11 Mar 2005 21:29:34 -0000 1.1 +++ address.c 5 Jun 2007 22:09:05 -0000 1.2 @@ -4,8 +4,7 @@ #include "address.h" uint64_t -uint64_from_hex_address (unsigned char *hex) +uint64_from_hex_address (char *hex) { return strtoll (hex, NULL, 16); } - Index: regexp_helper.h =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/regexp_helper.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- regexp_helper.h 11 Mar 2005 21:29:34 -0000 1.1 +++ regexp_helper.h 5 Jun 2007 22:09:06 -0000 1.2 @@ -1,7 +1,6 @@ #ifndef _REGEX_HELPER_H #define _REGEX_HELPER_H -extern int try_regexp (unsigned char *regexp, unsigned char *line, - int num_returns, ...); +extern int try_regexp (char *regexp, char *line, unsigned int num_returns, ...); #endif /* _REGEX_HELPER_H */ Index: regexp_helper.c =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/regexp_helper.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- regexp_helper.c 14 Mar 2005 08:54:37 -0000 1.2 +++ regexp_helper.c 5 Jun 2007 22:09:06 -0000 1.3 @@ -4,15 +4,15 @@ #include <stdlib.h> #include <string.h> #include <sys/types.h> +#include "regexp_helper.h" struct result_catcher { int match_index; - unsigned char **result; + char **result; }; int -try_regexp (unsigned char *regexp, unsigned char *line, - unsigned int num_returns, ...) +try_regexp (char *regexp, char *line, unsigned int num_returns, ...) { int regex_ret; regex_t regex; @@ -25,7 +25,7 @@ * Get memory for result catcher structures */ if (num_returns) { - int i; + unsigned int i; catch = malloc (num_returns * sizeof (struct result_catcher)); if (!catch) @@ -37,7 +37,7 @@ va_start (args, num_returns); { for (i = 0; i < num_returns; i++) { catch[i].match_index = va_arg (args, int); - catch[i].result = va_arg (args, unsigned char **); + catch[i].result = va_arg (args, char **); if (largest_match < catch[i].match_index) largest_match = catch[i].match_index; } @@ -48,8 +48,10 @@ * Compile the regex */ regex_ret = regcomp (®ex, regexp, REG_EXTENDED); - if (regex_ret != 0) + if (regex_ret != 0) { + fprintf (stderr, "%s: regcomp() = %d\n", __FUNCTION__, regex_ret); return -1; + } /* * If we need to supply a result, actually work towards getting @@ -71,7 +73,7 @@ */ regex_ret = regexec (®ex, line, match? largest_match + 1: 0, match, 0); if (regex_ret == 0) { - int i; + unsigned int i; unsigned int failure = 0; for (i = 0; i < num_returns; i++) @@ -79,18 +81,18 @@ failure++; if (failure) { + for (i = 0; i < num_returns; i++) + *(catch[i].result) = NULL; if (catch) free (catch); if (match) free (match); - for (i = 0; i < num_returns; i++) - *(catch[i].result) = NULL; regfree (®ex); return -1; } else { for (i = 0; i < num_returns; i++) *(catch[i].result) = strndup (line + match[catch[i].match_index].rm_so, - match[catch[i].match_index].rm_eo - match[catch[i].match_index].rm_so); + match[catch[i].match_index].rm_eo - match[catch[i].match_index].rm_so); if (catch) free (catch); if (match) @@ -99,16 +101,15 @@ return 0; } } else { - int i; + unsigned int i; + for (i = 0; i < num_returns; i++) + *(catch[i].result) = NULL; if (catch) free (catch); if (match) free (match); - for (i = 0; i < num_returns; i++) - *(catch[i].result) = NULL; regfree (®ex); return -1; } } - Index: address.h =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/address.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- address.h 11 Mar 2005 21:29:34 -0000 1.1 +++ address.h 5 Jun 2007 22:09:05 -0000 1.2 @@ -3,6 +3,6 @@ #include <stdint.h> -extern uint64_t uint64_from_hex_address (unsigned char *hex); +extern uint64_t uint64_from_hex_address (char *hex); #endif /* ADDRESS_H */ Index: parse.h =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/parse.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- parse.h 11 Mar 2005 21:29:34 -0000 1.1 +++ parse.h 5 Jun 2007 22:09:06 -0000 1.2 @@ -4,13 +4,13 @@ #define NUM_MATCHES 3 struct arch_parser_table { - unsigned char *regexp; - unsigned char *type; /* condjump, jump, ignore, ... */ + char *regexp; + char *type; /* condjump, jump, ignore, ... */ unsigned int arg[NUM_MATCHES]; #define MATCH_UNUSED ((unsigned int)-1) }; -extern int parse_line (unsigned char *line, struct arch_parser_table *table); +extern int parse_line (char *line, struct arch_parser_table *table); extern struct arch_parser_table vax_parser[]; extern struct arch_parser_table i386_parser[]; Index: parse_backend.c =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/parse_backend.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- parse_backend.c 14 Mar 2005 08:54:37 -0000 1.2 +++ parse_backend.c 5 Jun 2007 22:09:06 -0000 1.3 @@ -14,8 +14,7 @@ #endif static int -parse_condjump (unsigned char *line, unsigned char *line_address_hex, - unsigned char *jump_address_hex) +parse_condjump (char *line, char *line_address_hex, char *jump_address_hex) { uint64_t line_address; uint64_t jump_address; @@ -30,8 +29,7 @@ } static int -parse_jump (unsigned char *line, unsigned char *line_address_hex, - unsigned char *jump_address_hex) +parse_jump (char *line, char *line_address_hex, char *jump_address_hex) { uint64_t line_address; uint64_t jump_address; @@ -46,8 +44,7 @@ } static int -parse_ret (unsigned char *line, unsigned char *line_address_hex, - unsigned char *unused1) +parse_ret (char *line, char *line_address_hex, char *unused1) { uint64_t line_address; @@ -60,15 +57,13 @@ } static int -parse_ignore (unsigned char *line, unsigned char *unused1, - unsigned char *unused2) +parse_ignore (char *line, char *unused1, char *unused2) { return 0; } static int -parse_section (unsigned char *line, unsigned char *section_name, - unsigned char *unused1) +parse_section (char *line, char *section_name, char *unused1) { if (!line || !section_name) return -1; @@ -77,8 +72,7 @@ } static int -parse_function (unsigned char *line, unsigned char *function_name, - unsigned char *function_address_hex) +parse_function (char *line, char *function_name, char *function_address_hex) { uint64_t function_address; @@ -91,8 +85,7 @@ } static int -parse_code (unsigned char *line, unsigned char *line_address_hex, - unsigned char *unused1) +parse_code (char *line, char *line_address_hex, char *unused1) { uint64_t line_address; @@ -105,8 +98,8 @@ } static struct parser_func_table_entry { - unsigned char *name; - int (*parser_function) (unsigned char *arg1, unsigned char *arg2, unsigned char *arg3); + char *name; + int (*parser_function) (char *arg1, char *arg2, char *arg3); } function_table[] = { { .name = "condjump", &parse_condjump, }, { .name = "jump", &parse_jump, }, @@ -118,7 +111,7 @@ }; static void * -find_parse_function (unsigned char *name) +find_parse_function (char *name) { int i; @@ -130,10 +123,10 @@ } int -parse_line (unsigned char *line, struct arch_parser_table *arch) +parse_line (char *line, struct arch_parser_table *arch) { - unsigned char *arg[NUM_MATCHES]; - int (*parse_function) (unsigned char *, unsigned char *, unsigned char *); + char *arg[NUM_MATCHES]; + int (*parse_function) (char *, char *, char *); int ret; int i; unsigned int num_returns; @@ -219,4 +212,3 @@ return -1; } - Index: parse_vax.c =================================================================== RCS file: /cvsroot/linux-vax/usr/visualize_asm/parse_vax.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- parse_vax.c 12 Mar 2005 17:36:11 -0000 1.3 +++ parse_vax.c 5 Jun 2007 22:09:06 -0000 1.4 @@ -60,4 +60,3 @@ }, { }, }; - |