Article View: comp.bugs.2bsd
Article #175V1.21 (strncat is broken)
From: Keith Bostic
Date: Wed, 06 Jan 1988 20:02
Date: Wed, 06 Jan 1988 20:02
35 lines
1114 bytes
1114 bytes
Subject: strncat is broken
Index: lib/libc/pdp/gen/strncat.s 2.10BSD
Description:
strncat(3) doesn't truncate strings correctly.
Repeat-By:
The following program demonstrates the bug.
#include <stdio.h>
#include <strings.h>
main()
{
char *s = "This is a long string, but we'll truncate it at the comma";
s[21] = '\0';
printf("%s\n", s);
strncat(s, "Arragh!!", 7);
printf("%s\n", s);
}
Fix:
Apply the following patch.
*** strncat.s.orig Wed Jan 6 11:41:24 1988
--- strncat.s Wed Jan 6 11:41:34 1988
***************
*** 36,41 ****
--- 36,42 ----
movb (r2)+,(r1)+ / copy s2 to the end of s1 stopping at the
beq 3f / end of s2 or when n runs out ...
sob r0,2b
+ clrb (r1)
3:
mov (sp)+,r2 / restore r2
4:
Technical Details
Message-ID:
<8801062002.AA15696@okeeffe.Berkeley.EDU>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!rutgers!ucla-cs!zen!ucbvax!OKEEFFE.BERKELEY.EDU!bosticShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!rutgers!ucla-cs!zen!ucbvax!OKEEFFE.BERKELEY.EDU!bostic From: bostic@OKEEFFE.BERKELEY.EDU (Keith Bostic) Newsgroups: comp.bugs.2bsd Subject: V1.21 (strncat is broken) Message-ID: <8801062002.AA15696@okeeffe.Berkeley.EDU> Date: 6 Jan 88 20:02:27 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 35