Article View: gnu.utils.bug
Article #630shellutils-1.6: date bug with unknown FORMAT
From: 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
Technical Details
Message-ID:
<1992Aug26.152656.21923@news.eng.convex.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!convex.com!cyrusShow Full Headers
Complete Article Headers
Newsgroups: gnu.utils.bug Path: arc1-ca.pugleaf.net!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