components/psutils/patches/buffer_overflow.patch
changeset 1663 d64772b1eb67
equal deleted inserted replaced
1662:6f932ca78947 1663:d64772b1eb67
       
     1 The problem has been reported to [email protected] by mail but there was no
       
     2 response. For now it is safer to disable line wrapping than trying to fix
       
     3 various buffer overflows in the code.
       
     4 
       
     5 --- psutils/pserror.c	2014-01-23 15:47:09.375709690 +0100
       
     6 +++ psutils/pserror.c	2014-01-23 15:46:57.742698912 +0100
       
     7 @@ -12,111 +12,31 @@
       
     8  #include "patchlev.h"
       
     9  
       
    10  #include <string.h>
       
    11 +#include <stdio.h>
       
    12 +#include <stdarg.h>
       
    13  
       
    14  /* Message functions; there is a single are varargs functions for messages,
       
    15     warnings, and errors sent to stderr. If called with the flags MESSAGE_EXIT
       
    16     set, the routine does not return */
       
    17 -
       
    18 -#define MAX_MESSAGE	256	/* maximum formatted message length */
       
    19 -#define MAX_FORMAT	16	/* maximum format length */
       
    20 -#define MAX_COLUMN	78	/* maximum column to print upto */
       
    21 -
       
    22  void message(int flags, char *format, ...)
       
    23  {
       
    24    va_list args ;
       
    25 -  static column = 0 ;		/* current screen column for message wrap */
       
    26 -  char msgbuf[MAX_MESSAGE] ;	/* buffer in which to put the message */
       
    27 -  char *bufptr = msgbuf ;	/* message buffer pointer */
       
    28  
       
    29 -  if ( (flags & MESSAGE_NL) && column != 0 ) {	/* new line if not already */
       
    30 +  if ( flags & MESSAGE_NL ) {	/* new line if not already */
       
    31      putc('\n', stderr) ;
       
    32 -    column = 0 ;
       
    33    }
       
    34 -    
       
    35 +
       
    36    if ( flags & MESSAGE_PROGRAM ) {
       
    37 -    strcpy(bufptr, program) ;
       
    38 -    bufptr += strlen(program) ;
       
    39 -    *bufptr++ = ':' ;
       
    40 -    *bufptr++ = ' ' ;
       
    41 +    fprintf (stderr, "%s: ", program);
       
    42    }
       
    43  
       
    44    va_start(args, format) ;
       
    45 -  if ( format != NULL ) {
       
    46 -    char c ;
       
    47 -    while ( (c = *format++) != '\0' ) {
       
    48 -      if (c == '%') {
       
    49 -	int done, longform, index ;
       
    50 -	char fmtbuf[MAX_FORMAT] ;
       
    51 -	longform = index = 0 ;
       
    52 -	fmtbuf[index++] = c ;
       
    53 -	do {
       
    54 -	  done = 1 ;
       
    55 -	  fmtbuf[index++] = c = *format++ ;
       
    56 -	  fmtbuf[index] = '\0' ;
       
    57 -	  switch (c) {
       
    58 -	  case '%':
       
    59 -	    *bufptr++ = '%' ;
       
    60 -	  case '\0':
       
    61 -	    break ;
       
    62 -	  case 'e': case 'E': case 'f': case 'g': case 'G':
       
    63 -	    {
       
    64 -	      double d = va_arg(args, double) ;
       
    65 -	      sprintf(bufptr, fmtbuf, d) ;
       
    66 -	      bufptr += strlen(bufptr) ;
       
    67 -	    }
       
    68 -	    break ;
       
    69 -	  case 'c': case 'd': case 'i': case 'o':
       
    70 -	  case 'p': case 'u': case 'x': case 'X':
       
    71 -	    if ( longform ) {
       
    72 -	      long l = va_arg(args, long) ;
       
    73 -	      sprintf(bufptr, fmtbuf, l) ;
       
    74 -	    } else {
       
    75 -	      int i = va_arg(args, int) ;
       
    76 -	      sprintf(bufptr, fmtbuf, i) ;
       
    77 -	    }
       
    78 -	    bufptr += strlen(bufptr) ;
       
    79 -	    break ;
       
    80 -	  case 's':
       
    81 -	    {
       
    82 -	      char *s = va_arg(args, char *) ;
       
    83 -	      sprintf(bufptr, fmtbuf, s) ;
       
    84 -	      bufptr += strlen(bufptr) ;
       
    85 -	    }
       
    86 -	    break ;
       
    87 -	  case 'l':
       
    88 -	    longform = 1 ;
       
    89 -	    /* FALLTHRU */
       
    90 -	  default:
       
    91 -	    done = 0 ;
       
    92 -	  }
       
    93 -	} while ( !done ) ;
       
    94 -      } else if ( c == '\n' ) {	/* write out message so far and reset column */
       
    95 -	int len = bufptr - msgbuf ;	/* length of current message */
       
    96 -	*bufptr++ = '\n' ;
       
    97 -	*bufptr = '\0' ;
       
    98 -	if ( column + len > MAX_COLUMN && column > 0 ) {
       
    99 -	  putc('\n', stderr) ;
       
   100 -	  column = 0 ;
       
   101 -	}
       
   102 -	fputs(bufptr = msgbuf, stderr) ;
       
   103 -	column = 0 ;
       
   104 -      } else
       
   105 -	*bufptr++ = c ;
       
   106 -    }
       
   107 -    *bufptr = '\0' ;
       
   108 -    {
       
   109 -      int len = bufptr - msgbuf ;	/* length of current message */
       
   110 -      if ( column + len > MAX_COLUMN && column > 0 ) {
       
   111 -	putc('\n', stderr) ;
       
   112 -	column = 0 ;
       
   113 -      }
       
   114 -      fputs(msgbuf, stderr) ;
       
   115 -      column += len ;
       
   116 -    }
       
   117 -    fflush(stderr) ;
       
   118 -  }
       
   119 +  if ( format != NULL )
       
   120 +    vfprintf(stderr, format, args);
       
   121    va_end(args) ;
       
   122  
       
   123 +  fflush(stderr);
       
   124 +
       
   125    if ( flags & MESSAGE_EXIT )	/* don't return to program */
       
   126      exit(1) ;
       
   127  }