Replace some strncpy() by strlcpy().

This commit is contained in:
Peter Eisentraut 2007-02-07 00:52:35 +00:00
parent f11aa82d03
commit 16059d39a0
8 changed files with 20 additions and 30 deletions

View File

@ -4,7 +4,7 @@
* darcy@druid.net
* http://www.druid.net/darcy/
*
* $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.17 2006/07/14 05:28:27 tgl Exp $
* $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.18 2007/02/07 00:52:35 petere Exp $
* best viewed with tabs set to 4
*/
@ -76,8 +76,7 @@ chkpass_in(PG_FUNCTION_ARGS)
if (*str == ':')
{
result = (chkpass *) palloc(sizeof(chkpass));
strncpy(result->password, str + 1, 13);
result->password[13] = 0;
strlcpy(result->password, str + 1, 13 + 1);
PG_RETURN_POINTER(result);
}
@ -150,8 +149,7 @@ chkpass_eq(PG_FUNCTION_ARGS)
if (a2->vl_len < 12)
sz = a2->vl_len - 4;
strncpy(str, a2->vl_dat, sz);
str[sz] = 0;
strlcpy(str, a2->vl_dat, sz + 1);
PG_RETURN_BOOL(strcmp(a1->password, crypt(str, a1->password)) == 0);
}
@ -166,7 +164,6 @@ chkpass_ne(PG_FUNCTION_ARGS)
if (a2->vl_len < 12)
sz = a2->vl_len - 4;
strncpy(str, a2->vl_dat, sz);
str[sz] = 0;
strlcpy(str, a2->vl_dat, sz + 1);
PG_RETURN_BOOL(strcmp(a1->password, crypt(str, a1->password)) != 0);
}

View File

@ -8,7 +8,7 @@
* Darko Prenosil <Darko.Prenosil@finteh.hr>
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
*
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.61 2007/01/05 22:19:17 momjian Exp $
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.62 2007/02/07 00:52:35 petere Exp $
* Copyright (c) 2001-2007, PostgreSQL Global Development Group
* ALL RIGHTS RESERVED;
*
@ -2248,7 +2248,7 @@ createNewConnection(const char *name, remoteConn * rconn)
errmsg("duplicate connection name")));
hentry->rconn = rconn;
strncpy(hentry->name, name, NAMEDATALEN - 1);
strlcpy(hentry->name, name, sizeof(hentry->name));
}
static void

View File

@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.76 2007/01/26 20:06:52 tgl Exp $
* $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.77 2007/02/07 00:52:35 petere Exp $
*
* Since the server static private key ($DataDir/server.key)
* will normally be stored unencrypted so that the database
@ -933,8 +933,8 @@ aloop:
port->peer = SSL_get_peer_certificate(port->ssl);
if (port->peer == NULL)
{
strncpy(port->peer_dn, "(anonymous)", sizeof(port->peer_dn));
strncpy(port->peer_cn, "(anonymous)", sizeof(port->peer_cn));
strlcpy(port->peer_dn, "(anonymous)", sizeof(port->peer_dn));
strlcpy(port->peer_cn, "(anonymous)", sizeof(port->peer_cn));
}
else
{

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.93 2007/01/05 22:19:43 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.94 2007/02/07 00:52:35 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -539,8 +539,7 @@ find_in_dynamic_libpath(const char *basename)
len = piece - p;
piece = palloc(len + 1);
strncpy(piece, p, len);
piece[len] = '\0';
strlcpy(piece, p, len + 1);
mangled = substitute_libpath_macro(piece);
pfree(piece);

View File

@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.372 2007/02/01 19:10:28 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.373 2007/02/07 00:52:35 petere Exp $
*
*--------------------------------------------------------------------
*/
@ -5729,8 +5729,7 @@ ParseLongOption(const char *string, char **name, char **value)
if (string[equal_pos] == '=')
{
*name = guc_malloc(FATAL, equal_pos + 1);
strncpy(*name, string, equal_pos);
(*name)[equal_pos] = '\0';
strlcpy(*name, string, equal_pos + 1);
*value = guc_strdup(FATAL, &string[equal_pos + 1]);
}

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.157 2007/01/05 22:19:49 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.158 2007/02/07 00:52:35 petere Exp $
*/
/*----------------------------------------------------------------------
@ -2389,9 +2389,7 @@ previous_word(int point, int skip)
/* make a copy */
s = pg_malloc(end - start + 2);
strncpy(s, &rl_line_buffer[start], end - start + 1);
s[end - start + 1] = '\0';
strlcpy(s, &rl_line_buffer[start], end - start + 2);
return s;
}
@ -2460,8 +2458,7 @@ dequote_file_name(char *text, char quote_char)
length = strlen(text);
s = pg_malloc(length - 2 + 1);
strncpy(s, text +1, length - 2);
s[length] = '\0';
strlcpy(s, text +1, length - 2 + 1);
return s;
}

View File

@ -1,7 +1,7 @@
/*
* functions needed for descriptor handling
*
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/descriptor.c,v 1.24 2006/03/11 04:38:40 momjian Exp $
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/descriptor.c,v 1.25 2007/02/07 00:52:35 petere Exp $
*
* since descriptor might be either a string constant or a string var
* we need to check for a constant if we expect a constant
@ -323,7 +323,6 @@ descriptor_variable(const char *name, int input)
{descriptor_names[1], (struct ECPGtype *) & descriptor_type, 0, NULL}
};
strncpy(descriptor_names[input], name, MAX_DESCRIPTOR_NAMELEN);
descriptor_names[input][MAX_DESCRIPTOR_NAMELEN - 1] = 0;
strlcpy(descriptor_names[input], name, sizeof(descriptor_names[input]));
return (struct variable *) & varspace[input];
}

View File

@ -11,7 +11,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.28 2007/02/01 19:10:30 momjian Exp $
* $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.29 2007/02/07 00:52:35 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -349,8 +349,7 @@ replace_string(char *string, char *replace, char *replacement)
{
char *dup = strdup(string);
strncpy(string, dup, ptr - string);
string[ptr - string] = 0;
strlcpy(string, dup, ptr - string + 1);
strcat(string, replacement);
strcat(string, dup + (ptr - string) + strlen(replace));
free(dup);