home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / gnu / utils / bug / 1413 < prev    next >
Encoding:
Text File  |  1992-08-26  |  2.0 KB  |  73 lines

  1. Newsgroups: gnu.utils.bug
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!convex.com!cyrus
  3. From: cyrus@convex.com (Tait Cyrus)
  4. Subject: shellutils-1.6: date bug with unknown FORMAT
  5. Message-ID: <1992Aug26.152656.21923@news.eng.convex.com>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: Engineering, CONVEX Computer Corp., Colorado Springs, CO., USA
  8. Distribution: gnu
  9. Date: Wed, 26 Aug 1992 15:26:56 GMT
  10. Approved: bug-gnu-utils@prep.ai.mit.edu
  11. Lines: 60
  12.  
  13. shellutils-1.6/src/date.c has a bug in that if you pass an invalid format to
  14. it, like "date +%O", then date will go into an infinite loop allocating memory
  15. forever.  Below is a possible fix.  Another fix would be to limit the max
  16. size of 'out' in routine 'show_date' to some "reasonable" value, say like 10k
  17. and if the limit was reached, assume an invalid format.
  18.  
  19. *** date.c.ORG    Wed Aug 26 09:22:38 1992
  20. --- date.c    Wed Aug 26 09:23:54 1992
  21. ***************
  22. *** 175,180 ****
  23. --- 175,181 ----
  24.         printf ("%20.20s", asctime (tm));
  25.         format = "%Z %Y";
  26.       }
  27. +   if( check_format( format, tm ) ) return;
  28.     do
  29.       {
  30.         out_length += 200;
  31. ***************
  32. *** 183,188 ****
  33. --- 184,216 ----
  34.     while (strftime (out, out_length, format, tm) == 0);
  35.     printf ("%s\n", out);
  36.     free (out);
  37. + }
  38. + /*
  39. +  * Validate each part of the format.  Assume that no single part will produce
  40. +  * more than TMP_BUF_SIZE characters of output.
  41. +  */
  42. + #define TMP_BUF_SIZE 100
  43. + check_format( format, tm )
  44. +   char *format;
  45. +   struct tm *tm;
  46. + {
  47. +   char buf[TMP_BUF_SIZE];
  48. +   char op[3];
  49. +   while( *format ) {
  50. +     op[0] = *format++;
  51. +     if( *format ) op[1] = *format++;
  52. +     else op[1] = 0;
  53. +     op[2] = 0;
  54. +     if( strftime( buf, TMP_BUF_SIZE, op, tm ) == 0 )
  55. +       {
  56. +       printf("Unknown option '%s'\n", op );
  57. +       return(1);
  58. +       }
  59. +     }
  60. +   return(0);
  61.   }
  62.   
  63.   void
  64. -- 
  65. W. Tait Cyrus                   Software Engineer
  66. Convex Computer Corporation     cyrus@convex.com
  67. 2075 Research Parkway Suite B   719-594-4900 ext 41
  68. Colorado Springs, CO 80920
  69.  
  70.