home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12402 < prev    next >
Encoding:
Internet Message Format  |  1992-08-16  |  5.7 KB

  1. Xref: sparky comp.lang.c:12402 comp.programming:2347
  2. Newsgroups: comp.lang.c,comp.programming
  3. Path: sparky!uunet!gatech!bloom-beacon!bloom-picayune.mit.edu!news
  4. From: scs@adam.mit.edu (Steve Summit)
  5. Subject: Re: Allocate memory to typed in string, How?
  6. Message-ID: <1992Aug16.211644.6444@athena.mit.edu>
  7. Sender: news@athena.mit.edu (News system)
  8. Nntp-Posting-Host: adam.mit.edu
  9. Organization: none, at the moment
  10. References: <1992Aug13.184911.376@wyvern.twuug.com> <1992Aug15.201359.3601@athena.mit.edu>
  11. Date: Sun, 16 Aug 1992 21:16:44 GMT
  12. Lines: 97
  13.  
  14. In the context of assuming and/or imposing a limit on input line
  15. length, and in particular with respect to doing so on the basis
  16. of a restriction known to exist in the keyboard input subsystem
  17. of the computer being used, here's a fascinating little tidbit
  18. from the RISKS digest (aka comp.risks):
  19.  
  20. RISKS-LIST: RISKS-FORUM Digest  Wednesday 12 August 1992  Volume 13 : Issue 72
  21.  
  22. ------------------------------
  23.  
  24. Date: Tue, 11 Aug 92 14:56:31 MDT
  25. From: jhull@muse.den.mmc.com (Joseph F. Hull)
  26. Subject: Re: Stupid things people do
  27.  
  28. I was working as a programmer for a military command center, the kind with
  29. large screens around the walls which display current status of whatever.  The
  30. system was a custom job with custom software, but was fairly stable (no
  31. outstanding software problem reports, no recent modifications).  Normal
  32. operations 24 hours / day, 7 days / week.
  33.  
  34. One Monday morning about 0600, the system crashed.  No problem.  The operator
  35. initiated warm start on the hot backup system and dump procedures on the failed
  36. machine; back on-line in less than 3 minutes (and called me, midnight shift
  37. programming support).  A few minutes later the alternate system crashed.  What
  38. to do?  (The dump takes about 11 minutes.  If we abort the dump to get on-line
  39. as fast as possible, we lose any chance of finding out why the first crash
  40. occurred.  And the primary system may go down again if we have an unrepaired
  41. hardware problem.  But since both systems crashed within minutes of each other,
  42. its probably a software problem, so if I don't get the dump, we have ZERO
  43. chance of finding out what happened.)  Call the command post for permission to
  44. complete the dump.  Denied.  Abort the dump.  Reboot the primary.  Initiate
  45. dump on the alternate.  The primary crashes again.  Reboot the alternate.
  46. Initiate dump on the primary.  The alternate crashes again.  This time we get
  47. permission to allow the dumps to complete.  Reboot and back on-line.  By now,
  48. it's after 0700.
  49.  
  50. Start analyzing what happened.  Trace the problem to a data input routine.
  51. Hmmmmm. Seems like its overrunning the buffer and trashing an adjacent data
  52. structure.  Can't be, the buffer is already larger than the physical limit on
  53. the terminal (an IBM 2701 - a then modern but now ancient IBM Selectric
  54. ball-type typewriter rigged as a computer input device).  Quick fix: move the
  55. adjacent data structure further away from the buffer, re-assemble (Yes,
  56. Virginia, we had computers before we had compilers.  What's that, you little
  57. snot?  Yes, I did work on them and no it was not before Christ.), bring the
  58. alternate to "hot backup" status and do a switchover.  Take a deep breath and
  59. start figuring out WHY it happened, because the General has missed his Monday
  60. morning briefing and is going to want to know whether he cna count on his
  61. primary command and control system or not.
  62.  
  63. Hit a stone wall.  Couldn't find anything wrong with the code.  So I put an
  64. alarm in that input routine, took my chewing out and went on with life.  Two
  65. weeks later, my alarm went off.  The system didn't crash because I had moved
  66. that fragile data structure, but it would have if I hadn't moved it.  The alarm
  67. also triggered an on-line dump and, when I checked it, sure enough, that same
  68. terminal had overrun its buffer again.  But it can't!  The buffer is 128
  69. characters deep and the IBM 2701 is only 85 characters wide; you HAVE to enter
  70. a carriage return to continue.
  71.  
  72. Well, not quite.  I finally made the connection between one particular Major
  73. inputting data for the General's morning briefing and the alarms.  It seems
  74. this Major had figured out that the display screens could handle lines 132
  75. characters long even though the input devices could only provide 85.  So when
  76. he got to the end of a line on the terminal, he would grab the typewriter ball,
  77. drag it to the left, manually roll the paper forward and keep typing.  As long
  78. as he was entering less than 128 characters, everything was ok.  But when he
  79. went over that, ...
  80.  
  81. OBSERVATION 1:  A user will do anything (s)he can think of to get the job done.
  82. OBSERVATION 2:  They are usually more creative than we are, i.e., they think of
  83.                 things we don't.
  84.  
  85. Jeff Hull, 1544 S. Vaughn Cir, Aurora, CO 80012  303-977-1061  hull@den.mmc.com
  86.  
  87. ------------------------------
  88.  
  89. To Jeff's two observations we can of course add a few more:
  90.  
  91. OBSERVATION 3: Try not to depend on (i.e. make assumptions about)
  92. things outside the part of the system over which you have control.
  93. (In this case, the 2701 was well outside of the software module
  94. in question.)
  95.  
  96. OBSERVATION 4: Rather than assuming that something will never
  97. happen, guard against it.  In this case, don't assume that the
  98. input can't be longer than 128 characters, but rather test that
  99. it doesn't and in any case avoid overwriting that nonexistent
  100. 129th array element.  (Corollary: in C, use fgets rather than gets.)
  101.  
  102. OBSERVATION 5: Include run-time assertion checks to detect
  103. failures of assumptions which can occur at run time.  (This
  104. covers *all* assumptions, including those which under
  105. observation 3 shouldn't have been made in the first place.
  106. These run-time checks are obviously in addition to compile-time
  107. checks to detect failures of compile-time assumptions.)
  108.  
  109.                     Steve Summit
  110.                     scs@adam.mit.edu
  111.