Article View: news.software.readers
Article #38663Patch: trn seg faults on newsgroup names > 127 chars
From: Dan Harkless
Date: Thu, 12 Feb 1998 00:00
Date: Thu, 12 Feb 1998 00:00
93 lines
4327 bytes
4327 bytes
Howdy. For the last few weeks, trn4-test60 has been seg faulting on me,
right after it lists the first few newsgroups with unread news:
Connecting to news.speed.net...Done.
Unread news in a.bsu.programming 661 articles
Unread news in a.bsu.religion 86 articles
Unread news in a.bsu.talk 56 articles
Unread news in aaa.inu-chan 5 articles
Unread news in ab.general 86 articles
etc.
Caught a SIGSEGV--.newsrc restored
Abort
trn 3.6 does the same thing. I tried installing the latest, trn4-test61,
but it behaved the same way. I tried configuring not to use vfork(), since
Configure says "some systems" have problems with it. Didn't help. Tried
compiling with gcc instead of HP-UX 10.20 cc. No dice.
Finally, I compiled test61 with debug support. Running with -D didn't
uncover anything useful, so finally I ran trn in the debugger. There I
found that it was seg faulting on line 231 of the hash() function:
230: while (keylen--)
> 231: hash += *key++;
This is because it was called with keylen == -97. It ran amok through
memory until keylen got to -102866 and then seg faulted.
I ran up the call stack and traced the computation of keylen to the
parse_rcline() function, called just before hashfetch(). Here we find the
very surprising line 690.
669: static void
670: parse_rcline(np)
671: register NGDATA* np;
672: {
673: char* s;
674: int len;
675:
676: for (s=np->rcline; *s && *s!=':' && *s!=NEGCHAR && !isspace(*s); s++) ;
677: len = s - np->rcline;
678: if ((!*s || isspace(*s)) && !checkflag) {
679: #ifndef lint
680: np->rcline = saferealloc(np->rcline,(MEM_SIZE)len + 3);
681: #endif
682: s = np->rcline + len;
683: strcpy(s, ": ");
684: }
685: if (*s == ':' && s[1] && s[2] == '0') {
686: np->flags |= NF_UNTHREADED;
687: s[2] = '1';
688: }
689: np->subscribechar = *s; /* salt away the : or ! */
> 690: np->numoffset = (char)len + 1;
691: /* remember where the numbers are */
692: *s = '\0'; /* null terminate newsgroup name */
693: }
'len' is an int. 'np->numoffset' is an int. But for some reason for the
duration of the expression, we pretend we're dealing with 7 bit signed
values. Why?!?
My news server is carrying a newsgroup called:
alt.karl-kleinpaste.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die.die
The len is 159, but then we cast to a char for some reason, overflow, and
get -96. If the cast is removed:
moldavia-root> diff rcstuff.c.orig rcstuff.c
690c690
< np->numoffset = (char)len + 1;
---
> np->numoffset = len + 1;
Everything works great, as expected.
So, the two questions become:
1. Why the heck was that data-chopping cast in there?
2. Am I really the only person in the world using trn whose news server
carries a group with a name longer than 127 characters???
--
Dan Harkless Unitech Research, Inc. <dan_feb98@unitech.com>
NOTE: This is a monthly mail alias used to post to the Usenet without
conSPAMinating my real address. If you are replying after February 1998,
your mail may bounce. If so, replace 'feb' with the current month's abbrev.
Technical Details
Message-ID:
<6bttmf$cer$1@speedx1.speed.net>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mailShow Full Headers
Complete Article Headers
Message-ID: <6bttmf$cer$1@speedx1.speed.net> Subject: Patch: trn seg faults on newsgroup names > 127 chars Date: Thu, 12 Feb 1998 00:00:00 +0000 From: Dan Harkless <dan_feb98@unitech.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.mbox.zip!not-for-mail X-Deja-AN: 324339423 Organization: Unitech Research, Inc. -- Irvine, California, USA Newsgroups: news.software.readers Originator: dlh@unitech.com (Dan L. Harkless)