home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / bugs / sys5 / 145 < prev    next >
Encoding:
Text File  |  1992-12-12  |  3.8 KB  |  110 lines

  1. Newsgroups: comp.bugs.sys5
  2. Path: sparky!uunet!gatech!hubcap!ncrcae!jutland.ColumbiaSC.NCR.COM!bam
  3. From: bam@jutland.ColumbiaSC.NCR.COM (Bo Muldbak)
  4. Subject: Re: putenv() is clobbering static data!  NCR 3xxx NCR OS 2.0 (SVR4)
  5. Message-ID: <1992Dec12.083958.9579@ncrcae.ColumbiaSC.NCR.COM>
  6. Followup-To: comp.bugs.sys5
  7. Nntp-Posting-Host: jutland.columbiasc.ncr.com
  8. Reply-To: Bo.Muldbak@ColumbiaSC.NCR.COM
  9. Organization: NCR Corporation, MCPD Columbia SC.
  10. References: <1992Dec9.091253.26269@informix.com>
  11. Date: Sat, 12 Dec 92 13:39:58 GMT
  12. Lines: 96
  13.  
  14. In article <1992Dec9.091253.26269@informix.com> (Colonel Panic) writes:
  15. |> I've run into a nasty bug on NCR, but I can't yet be sure whether this
  16. |> is a USL-generic thing or NCR-specific.
  17.  
  18.  
  19. Well, to prove it a "nasty bug on NCR", I think you will have to explain
  20. a bit closer what you are doing.  See below.
  21.  
  22.  
  23. |> 
  24. |> The scenario: I have a socket-accepting daemon that forks children for
  25. |> each new accepted connection over an RF link.  Pretty basic stuff.
  26. |> At one point, I call putenv() to replace PATH in the user's environment
  27. |> (a security measure; long story).  I assemble my new variable into a
  28.  
  29.  
  30.  
  31. Do you replace with a fixed string or with an edited version of the
  32. current PATH. If last mentioned is the case, try running your application 
  33. with a small path like
  34.  
  35.     PATH=/tmp;.    YourApplication
  36.  
  37.  
  38. |> (static) character buffer declared above main (*not* an automatic
  39. |> variable, I'm not *quite* that punchy yet), call putenv(), putenv()
  40. |> returns zero, AND CLOBBERS MY SOCKET HANDLE! (a (static) int). 
  41.  
  42.  
  43. Is the socket handle declared right after your buffer, and if not
  44. are variables between them clobbered too? From below we already know,
  45. that stuff behind your socket handle variable must have been clobbered.
  46.  
  47.  
  48. |> What was (5) becomes (1835413345) as an immediate result of the putenv(). 
  49. |> 
  50.  
  51. Have you noticed, that 1835413345 = 0x6d662f61 = "mf/a" ?
  52. With an Intel based machine meaning, that your path contains substring 
  53. "a/fm". If you dump the bytes behind the socket handle variable you would
  54. probably find the rest of the path. At the very least you will find the Null
  55. byte ending this string.
  56.  
  57. putenv will never try to write to your string variable. Uses only the pointer
  58. parameter you give it. As specified by the man-page for putenv
  59. it manipulates the environment pointed to by "environ". A simple
  60. table of string pointers. Of which one of them is yours.
  61.  
  62. Without a testprogram showing this, I must admit, that this seem
  63. a classic case of a couple of "strcat"s running wild to me. Simple
  64. overwrite.  Working with PATH values, you should take extreme care
  65. of the size of the buffers. You can never assume anything about the size
  66. of the PATH used by your end users. It may work fine in your environment
  67. with a fixed size buffer, but tomorrow you are delivering your product to a
  68. customer with a very wild and long PATH variable. Unless you are willing to
  69. preallocate wiiillldddd buffersizes; work dynamic... Never trust users. :-))
  70.  
  71.  
  72.  
  73. |> The string being putenv'd is about 340 bytes long.  I don't know yet 
  74. |> if anything else gets clobbered.
  75.  
  76.  
  77.  
  78. As seen from above I would think thats what you would expect.
  79.  
  80.  
  81.  
  82. |> 
  83. |> All of this works fine on Sun and HP/UX (among others), but this is
  84. |> the first SVR4 we've tried it on.   
  85. |> 
  86. |> Any ideas out there?
  87. |> 
  88. |> Version info:
  89. |> cat /etc/.relid
  90. |> 051992 RELEASE 010300 Prerelease Version 04 NST OS
  91. |> uname -a
  92. |> ncr486 ncr486 4.0 2.0 3314 386/486/MC
  93.  
  94.  
  95.  
  96. All the above is NCR specific info, and will not mean anything
  97. to people outside NCR. Unfortunately. :-()
  98.  
  99. The above is a 4.0.x equivalent.
  100.  
  101.     Hope this helps, Mr. Panic. :-))
  102.  
  103.         Bo
  104.  
  105. -- 
  106. Bo Asbjorn Muldbak             // Email:  Bo.Muldbak@ColumbiaSC.NCR.COM
  107. Unix Systems Business Unit     // Phone:  +1 (803) 791-6871
  108. NCR Corporation, MCPD-Columbia // Fax  :  +1 (803) 739-7371
  109. All standard disclaimers apply // Wizards? Where, when, why? I'm an atheist..
  110.