Thread View: gnu.utils.bug
1 messages
1 total messages
Started by Tait Cyrus
Wed, 26 Aug 1992 15:26
shellutils-1.6: date bug with unknown FORMAT
Author: Tait Cyrus
Date: Wed, 26 Aug 1992 15:26
Date: Wed, 26 Aug 1992 15:26
59 lines
2118 bytes
2118 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads