Off by 1 adjustment. Properly NUL terminate after strncpy.

Obtained from: {Net|Open}BSD
This commit is contained in:
charnier 1997-06-02 06:30:06 +00:00
parent 9b043dcc94
commit 961f5b3e1a
3 changed files with 11 additions and 7 deletions

View File

@ -34,7 +34,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
* $Id: cache.c,v 1.6 1997/02/22 14:04:21 peter Exp $
*/
#ifndef lint
@ -255,7 +255,7 @@ name_uid(uid, frc)
if (ptr == NULL)
return(pw->pw_name);
ptr->uid = uid;
(void)strncpy(ptr->name, pw->pw_name, UNMLEN);
(void)strncpy(ptr->name, pw->pw_name, UNMLEN - 1);
ptr->name[UNMLEN-1] = '\0';
ptr->valid = VALID;
}
@ -332,7 +332,7 @@ name_gid(gid, frc)
if (ptr == NULL)
return(gr->gr_name);
ptr->gid = gid;
(void)strncpy(ptr->name, gr->gr_name, GNMLEN);
(void)strncpy(ptr->name, gr->gr_name, GNMLEN - 1);
ptr->name[GNMLEN-1] = '\0';
ptr->valid = VALID;
}
@ -398,7 +398,7 @@ uid_name(name, uid)
*uid = pw->pw_uid;
return(0);
}
(void)strncpy(ptr->name, name, UNMLEN);
(void)strncpy(ptr->name, name, UNMLEN - 1);
ptr->name[UNMLEN-1] = '\0';
if ((pw = getpwnam(name)) == NULL) {
ptr->valid = INVALID;
@ -468,7 +468,7 @@ gid_name(name, gid)
return(0);
}
(void)strncpy(ptr->name, name, GNMLEN);
(void)strncpy(ptr->name, name, GNMLEN - 1);
ptr->name[GNMLEN-1] = '\0';
if ((gr = getgrnam(name)) == NULL) {
ptr->valid = INVALID;

View File

@ -34,7 +34,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
* $Id: pat_rep.c,v 1.8 1997/02/22 14:04:35 peter Exp $
*/
#ifndef lint
@ -776,6 +776,7 @@ tty_rename(arcn)
tty_prnt("Processing continues, name changed to: %s\n", tmpname);
res = add_name(arcn->name, arcn->nlen, tmpname);
arcn->nlen = l_strncpy(arcn->name, tmpname, PAXPATHLEN+1);
arcn->name[PAXPATHLEN] = '\0';
if (res < 0)
return(-1);
return(0);
@ -1056,6 +1057,7 @@ rep_name(name, nlen, prnt)
if (*nname == '\0')
return(1);
*nlen = l_strncpy(name, nname, PAXPATHLEN + 1);
name[PAXPATHLEN] = '\0';
}
return(0);
}

View File

@ -34,7 +34,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
* $Id: tables.c,v 1.7 1997/02/22 14:04:43 peter Exp $
*/
#ifndef lint
@ -180,6 +180,7 @@ chk_lnk(arcn)
*/
arcn->ln_nlen = l_strncpy(arcn->ln_name, pt->name,
PAXPATHLEN+1);
arcn->ln_name[PAXPATHLEN] = '\0';
if (arcn->type == PAX_REG)
arcn->type = PAX_HRG;
else
@ -655,6 +656,7 @@ sub_name(oname, onamelen)
* and return (we know that oname has enough space)
*/
*onamelen = l_strncpy(oname, pt->nname, PAXPATHLEN+1);
oname[PAXPATHLEN] = '\0';
return;
}
pt = pt->fow;