🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.2bsd
Article #233

mkstr truncates strings and converts octal wrong +FIX

#233
From: Steven M. Schultz
Date: Thu, 06 Apr 1989 05:14
60 lines
1945 bytes
Description:
	'mkstr' incorrectly processes octal numbers in strings.

	Characters of the form \ooo where 'o' is an octal digit
	possibly result in a truncated string (if the first digit
	is 0) AND definitely result in an incorrect value if more
	than one digit is present.

Repeat-By:
	Run 'mkstr' on a file having a string of the form "foo\001bar".
	Note that only "foo\0" makes it to the output.  Guess "0" 
	wasn't considered an octal digit at some point in the past ;-)

	Run 'mkstr' on a file having a string of the form "foo\13", note
	that "foo\203" is the result.  This is a result of shifting by
	7 instead of three in the conversion process.

Fix:
	Apply the following patch to mkstr.c, the extra assign of -1 to ch
	wasn't needed anyway.

*** mkstr.c.old	Wed Apr  5 21:20:30 1989
--- mkstr.c	Wed Apr  5 21:27:03 1989
***************
*** 164,172 ****
  			case 'f':
  				c = '\f';
  				break;
- 			case '0':
- 				c = 0;
- 				break;
  			case '\\':
  				break;
  			default:
--- 164,169 ----
***************
*** 176,186 ****
  				ch = getchar();
  				if (!octdigit(ch))
  					break;
! 				c <<= 7, c += ch - '0';
  				ch = getchar();
  				if (!octdigit(ch))
  					break;
! 				c <<= 3, c+= ch - '0', ch = -1;
  				break;
  			}
  		}
--- 173,183 ----
  				ch = getchar();
  				if (!octdigit(ch))
  					break;
! 				c <<= 3, c += ch - '0';
  				ch = getchar();
  				if (!octdigit(ch))
  					break;
! 				c <<= 3, c += ch - '0';
  				break;
  			}
  		}
Technical Details
Message-ID: <28903@wlbr.EATON.COM>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!ames!elroy!mahendo!wlbr!sms

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!lll-winken!ames!elroy!mahendo!wlbr!sms
From: sms@etn-wlv.eaton.com (Steven M. Schultz)
Newsgroups: comp.bugs.2bsd
Subject: mkstr truncates strings and converts octal wrong +FIX
Message-ID: <28903@wlbr.EATON.COM>
Date: 6 Apr 89 05:14:54 GMT
Sender: news@wlbr.EATON.COM
Reply-To: sms@etn-wlv.eaton.com (Steven M. Schultz)
Organization: Contel Federal Systems
Lines: 60