home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.utils.bug
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!convex.com!cyrus
- From: cyrus@convex.com (Tait Cyrus)
- Subject: shellutils-1.6: date bug with unknown FORMAT
- Message-ID: <1992Aug26.152656.21923@news.eng.convex.com>
- Sender: gnulists@ai.mit.edu
- Organization: Engineering, CONVEX Computer Corp., Colorado Springs, CO., USA
- Distribution: gnu
- Date: Wed, 26 Aug 1992 15:26:56 GMT
- Approved: bug-gnu-utils@prep.ai.mit.edu
- Lines: 60
-
- shellutils-1.6/src/date.c has a bug in that if you pass an invalid format to
- it, like "date +%O", then date will go into an infinite loop allocating memory
- forever. Below is a possible fix. Another fix would be to limit the max
- size of 'out' in routine 'show_date' to some "reasonable" value, say like 10k
- and if the limit was reached, assume an invalid format.
-
- *** date.c.ORG Wed Aug 26 09:22:38 1992
- --- date.c Wed Aug 26 09:23:54 1992
- ***************
- *** 175,180 ****
- --- 175,181 ----
- printf ("%20.20s", asctime (tm));
- format = "%Z %Y";
- }
- + if( check_format( format, tm ) ) return;
- do
- {
- out_length += 200;
- ***************
- *** 183,188 ****
- --- 184,216 ----
- while (strftime (out, out_length, format, tm) == 0);
- printf ("%s\n", out);
- free (out);
- + }
- +
- + /*
- + * Validate each part of the format. Assume that no single part will produce
- + * more than TMP_BUF_SIZE characters of output.
- + */
- + #define TMP_BUF_SIZE 100
- +
- + check_format( format, tm )
- + char *format;
- + struct tm *tm;
- + {
- + char buf[TMP_BUF_SIZE];
- + char op[3];
- +
- + while( *format ) {
- + op[0] = *format++;
- + if( *format ) op[1] = *format++;
- + else op[1] = 0;
- + op[2] = 0;
- + if( strftime( buf, TMP_BUF_SIZE, op, tm ) == 0 )
- + {
- + printf("Unknown option '%s'\n", op );
- + return(1);
- + }
- + }
- + return(0);
- }
-
- void
- --
- W. Tait Cyrus Software Engineer
- Convex Computer Corporation cyrus@convex.com
- 2075 Research Parkway Suite B 719-594-4900 ext 41
- Colorado Springs, CO 80920
-
-