diff options
author | Peter Eisentraut | 2007-02-07 00:52:35 +0000 |
---|---|---|
committer | Peter Eisentraut | 2007-02-07 00:52:35 +0000 |
commit | b630ea587d524e5cd20463a51a72eb55d2ac4c35 (patch) | |
tree | dae693976e6c7b6741a739e2db5857767b061775 | |
parent | 5b0af8870eff545ccdb02d8dc385eeb52c4843e5 (diff) |
Replace some strncpy() by strlcpy().
-rw-r--r-- | contrib/chkpass/chkpass.c | 9 | ||||
-rw-r--r-- | contrib/dblink/dblink.c | 2 | ||||
-rw-r--r-- | src/backend/libpq/be-secure.c | 4 | ||||
-rw-r--r-- | src/backend/utils/fmgr/dfmgr.c | 3 | ||||
-rw-r--r-- | src/backend/utils/misc/guc.c | 3 | ||||
-rw-r--r-- | src/bin/psql/tab-complete.c | 7 | ||||
-rw-r--r-- | src/interfaces/ecpg/preproc/descriptor.c | 3 | ||||
-rw-r--r-- | src/test/regress/pg_regress.c | 3 |
8 files changed, 12 insertions, 22 deletions
diff --git a/contrib/chkpass/chkpass.c b/contrib/chkpass/chkpass.c index 9a92ca71b0..2103ca1c03 100644 --- a/contrib/chkpass/chkpass.c +++ b/contrib/chkpass/chkpass.c @@ -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); } diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index 10469622a9..e5e5663f21 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -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 diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c index f4ba655f4e..1a907e8b9b 100644 --- a/src/backend/libpq/be-secure.c +++ b/src/backend/libpq/be-secure.c @@ -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 { diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c index b3702aa3a0..d3dc65475b 100644 --- a/src/backend/utils/fmgr/dfmgr.c +++ b/src/backend/utils/fmgr/dfmgr.c @@ -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); diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index fd3fb20d8f..5d945e39c4 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -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]); } diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 25e377d81f..1924119451 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -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; } diff --git a/src/interfaces/ecpg/preproc/descriptor.c b/src/interfaces/ecpg/preproc/descriptor.c index d4266ff187..ee440b3525 100644 --- a/src/interfaces/ecpg/preproc/descriptor.c +++ b/src/interfaces/ecpg/preproc/descriptor.c @@ -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]; } diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c index c01fb7c159..5f4fafea85 100644 --- a/src/test/regress/pg_regress.c +++ b/src/test/regress/pg_regress.c @@ -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); |