Ethereal-dev: [ethereal-dev] Re: core dump

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <gharris@xxxxxxxxxxxx>
Date: Mon, 21 Feb 2000 00:14:23 -0800
> #0  _IO_fputs (
>     str=0xbfffee38 "     37 14:35:12.2615   129.142.7.100
> 130.228.222.123       DNS      Standard query response CNAME www.sol.no A
> 195.225.3.46 A 195.225.2.59 A 195.225.3.50 A 195.225.2.37 A 195.225.3.37 A
> 195.2"..., fp=0x0) at iofputs.c:39

Hmm.  That's a bit of a long line; perhaps it could be too long for the
fixed-size buffer in the code to print packet summaries?

Yes, in fact, it is; "www.sol.no" has enough different IP addresses that
the summary line is too long for the buffer.

I've attached a patch to "file.c" to dynamically allocate the line
buffer for summaries (and free it when done); you'd need to download the
Ethereal source, apply the patch with "patch", and rebuild it.

I'll check the patch into the Ethereal CVS source tree, so that the fix
should show up in the next release.
Index: file.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/file.c,v
retrieving revision 1.166
diff -c -r1.166 file.c
*** file.c	2000/02/19 14:00:34	1.166
--- file.c	2000/02/21 08:13:49
***************
*** 849,856 ****
    gtk_clist_thaw(GTK_CLIST(packet_list));
  }
  
- #define	MAX_LINE_LENGTH	256
- 
  int
  print_packets(capture_file *cf, print_args_t *print_args)
  {
--- 849,854 ----
***************
*** 863,871 ****
    gint       *col_widths = NULL;
    gint        data_width;
    gboolean    print_separator;
!   char        line_buf[MAX_LINE_LENGTH+1];	/* static-sized buffer! */
    char        *cp;
!   int         sprintf_len;
  
    cf->print_fh = open_print_dest(print_args->to_file, print_args->dest);
    if (cf->print_fh == NULL)
--- 861,871 ----
    gint       *col_widths = NULL;
    gint        data_width;
    gboolean    print_separator;
!   char       *line_buf = NULL;
!   int         line_buf_len = 256;
    char        *cp;
!   int         column_len;
!   int         line_len;
  
    cf->print_fh = open_print_dest(print_args->to_file, print_args->dest);
    if (cf->print_fh == NULL)
***************
*** 874,886 ****
    print_preamble(cf->print_fh, print_args->format);
  
    if (print_args->print_summary) {
!     /* We're printing packet summaries.
  
!        Find the widths for each of the columns - maximum of the
         width of the title and the width of the data - and print
         the column titles. */
      col_widths = (gint *) g_malloc(sizeof(gint) * cf->cinfo.num_cols);
      cp = &line_buf[0];
      for (i = 0; i < cf->cinfo.num_cols; i++) {
        /* Don't pad the last column. */
        if (i == cf->cinfo.num_cols - 1)
--- 874,889 ----
    print_preamble(cf->print_fh, print_args->format);
  
    if (print_args->print_summary) {
!     /* We're printing packet summaries.  Allocate the line buffer at
!        its initial length. */
!     line_buf = g_malloc(line_buf_len + 1);
  
!     /* Find the widths for each of the columns - maximum of the
         width of the title and the width of the data - and print
         the column titles. */
      col_widths = (gint *) g_malloc(sizeof(gint) * cf->cinfo.num_cols);
      cp = &line_buf[0];
+     line_len = 0;
      for (i = 0; i < cf->cinfo.num_cols; i++) {
        /* Don't pad the last column. */
        if (i == cf->cinfo.num_cols - 1)
***************
*** 892,903 ****
            col_widths[i] = data_width;
        }
  
        /* Right-justify the packet number column. */
        if (cf->cinfo.col_fmt[i] == COL_NUMBER)
!         sprintf_len = sprintf(cp, "%*s", col_widths[i], cf->cinfo.col_title[i]);
        else
!         sprintf_len = sprintf(cp, "%-*s", col_widths[i], cf->cinfo.col_title[i]);
!       cp += sprintf_len;
        if (i == cf->cinfo.num_cols - 1)
          *cp++ = '\n';
        else
--- 895,919 ----
            col_widths[i] = data_width;
        }
  
+       /* Find the length of the string for this column. */
+       column_len = strlen(cf->cinfo.col_title[i]);
+       if (col_widths[i] > column_len)
+         column_len = col_widths[i];
+ 
+       /* Make sure there's room in the line buffer for the column; if not,
+          double its length. */
+       line_len += column_len + 1;	/* "+1" for space or \n */
+       if (line_len > line_buf_len) {
+         line_buf_len *= 2;
+         line_buf = g_realloc(line_buf, line_buf_len + 1);
+       }
+ 
        /* Right-justify the packet number column. */
        if (cf->cinfo.col_fmt[i] == COL_NUMBER)
!         sprintf(cp, "%*s", col_widths[i], cf->cinfo.col_title[i]);
        else
!         sprintf(cp, "%-*s", col_widths[i], cf->cinfo.col_title[i]);
!       cp += column_len;
        if (i == cf->cinfo.num_cols - 1)
          *cp++ = '\n';
        else
***************
*** 954,966 ****
          dissect_packet(cf->pd, fd, NULL);
          fill_in_columns(fd);
          cp = &line_buf[0];
          for (i = 0; i < cf->cinfo.num_cols; i++) {
            /* Right-justify the packet number column. */
            if (cf->cinfo.col_fmt[i] == COL_NUMBER)
!             sprintf_len = sprintf(cp, "%*s", col_widths[i], cf->cinfo.col_data[i]);
            else
!             sprintf_len = sprintf(cp, "%-*s", col_widths[i], cf->cinfo.col_data[i]);
!           cp += sprintf_len;
            if (i == cf->cinfo.num_cols - 1)
              *cp++ = '\n';
            else
--- 970,996 ----
          dissect_packet(cf->pd, fd, NULL);
          fill_in_columns(fd);
          cp = &line_buf[0];
+         line_len = 0;
          for (i = 0; i < cf->cinfo.num_cols; i++) {
+           /* Find the length of the string for this column. */
+           column_len = strlen(cf->cinfo.col_data[i]);
+           if (col_widths[i] > column_len)
+             column_len = col_widths[i];
+ 
+           /* Make sure there's room in the line buffer for the column; if not,
+              double its length. */
+           line_len += column_len + 1;	/* "+1" for space or \n */
+           if (line_len > line_buf_len) {
+             line_buf_len *= 2;
+             line_buf = g_realloc(line_buf, line_buf_len + 1);
+           }
+ 
            /* Right-justify the packet number column. */
            if (cf->cinfo.col_fmt[i] == COL_NUMBER)
!             sprintf(cp, "%*s", col_widths[i], cf->cinfo.col_data[i]);
            else
!             sprintf(cp, "%-*s", col_widths[i], cf->cinfo.col_data[i]);
!           cp += column_len;
            if (i == cf->cinfo.num_cols - 1)
              *cp++ = '\n';
            else
***************
*** 996,1001 ****
--- 1026,1033 ----
  
    if (col_widths != NULL)
      g_free(col_widths);
+   if (line_buf != NULL)
+     g_free(line_buf);
  
    print_finale(cf->print_fh, print_args->format);