Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16059d3

Browse files
committed
Replace some strncpy() by strlcpy().
1 parentf11aa82 commit16059d3

File tree

8 files changed

+20
-30
lines changed

8 files changed

+20
-30
lines changed

‎contrib/chkpass/chkpass.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* darcy@druid.net
55
* http://www.druid.net/darcy/
66
*
7-
* $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.17 2006/07/14 05:28:27 tgl Exp $
7+
* $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.18 2007/02/07 00:52:35 petere Exp $
88
* best viewed with tabs set to 4
99
*/
1010

@@ -76,8 +76,7 @@ chkpass_in(PG_FUNCTION_ARGS)
7676
if (*str==':')
7777
{
7878
result= (chkpass*)palloc(sizeof(chkpass));
79-
strncpy(result->password,str+1,13);
80-
result->password[13]=0;
79+
strlcpy(result->password,str+1,13+1);
8180
PG_RETURN_POINTER(result);
8281
}
8382

@@ -150,8 +149,7 @@ chkpass_eq(PG_FUNCTION_ARGS)
150149

151150
if (a2->vl_len<12)
152151
sz=a2->vl_len-4;
153-
strncpy(str,a2->vl_dat,sz);
154-
str[sz]=0;
152+
strlcpy(str,a2->vl_dat,sz+1);
155153
PG_RETURN_BOOL(strcmp(a1->password,crypt(str,a1->password))==0);
156154
}
157155

@@ -166,7 +164,6 @@ chkpass_ne(PG_FUNCTION_ARGS)
166164

167165
if (a2->vl_len<12)
168166
sz=a2->vl_len-4;
169-
strncpy(str,a2->vl_dat,sz);
170-
str[sz]=0;
167+
strlcpy(str,a2->vl_dat,sz+1);
171168
PG_RETURN_BOOL(strcmp(a1->password,crypt(str,a1->password))!=0);
172169
}

‎contrib/dblink/dblink.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Darko Prenosil <Darko.Prenosil@finteh.hr>
99
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
1010
*
11-
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.61 2007/01/05 22:19:17 momjian Exp $
11+
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.62 2007/02/07 00:52:35 petere Exp $
1212
* Copyright (c) 2001-2007, PostgreSQL Global Development Group
1313
* ALL RIGHTS RESERVED;
1414
*
@@ -2248,7 +2248,7 @@ createNewConnection(const char *name, remoteConn * rconn)
22482248
errmsg("duplicate connection name")));
22492249

22502250
hentry->rconn=rconn;
2251-
strncpy(hentry->name,name,NAMEDATALEN-1);
2251+
strlcpy(hentry->name,name,sizeof(hentry->name));
22522252
}
22532253

22542254
staticvoid

‎src/backend/libpq/be-secure.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.76 2007/01/26 20:06:52 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/libpq/be-secure.c,v 1.77 2007/02/07 00:52:35 petere Exp $
1515
*
1616
* Since the server static private key ($DataDir/server.key)
1717
* will normally be stored unencrypted so that the database
@@ -933,8 +933,8 @@ open_server_SSL(Port *port)
933933
port->peer=SSL_get_peer_certificate(port->ssl);
934934
if (port->peer==NULL)
935935
{
936-
strncpy(port->peer_dn,"(anonymous)",sizeof(port->peer_dn));
937-
strncpy(port->peer_cn,"(anonymous)",sizeof(port->peer_cn));
936+
strlcpy(port->peer_dn,"(anonymous)",sizeof(port->peer_dn));
937+
strlcpy(port->peer_cn,"(anonymous)",sizeof(port->peer_cn));
938938
}
939939
else
940940
{

‎src/backend/utils/fmgr/dfmgr.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.93 2007/01/05 22:19:43 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.94 2007/02/07 00:52:35 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -539,8 +539,7 @@ find_in_dynamic_libpath(const char *basename)
539539
len=piece-p;
540540

541541
piece=palloc(len+1);
542-
strncpy(piece,p,len);
543-
piece[len]='\0';
542+
strlcpy(piece,p,len+1);
544543

545544
mangled=substitute_libpath_macro(piece);
546545
pfree(piece);

‎src/backend/utils/misc/guc.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.372 2007/02/01 19:10:28 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.373 2007/02/07 00:52:35 petere Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -5729,8 +5729,7 @@ ParseLongOption(const char *string, char **name, char **value)
57295729
if (string[equal_pos]=='=')
57305730
{
57315731
*name=guc_malloc(FATAL,equal_pos+1);
5732-
strncpy(*name,string,equal_pos);
5733-
(*name)[equal_pos]='\0';
5732+
strlcpy(*name,string,equal_pos+1);
57345733

57355734
*value=guc_strdup(FATAL,&string[equal_pos+1]);
57365735
}

‎src/bin/psql/tab-complete.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.157 2007/01/05 22:19:49 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.158 2007/02/07 00:52:35 petere Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -2389,9 +2389,7 @@ previous_word(int point, int skip)
23892389

23902390
/* make a copy */
23912391
s=pg_malloc(end-start+2);
2392-
2393-
strncpy(s,&rl_line_buffer[start],end-start+1);
2394-
s[end-start+1]='\0';
2392+
strlcpy(s,&rl_line_buffer[start],end-start+2);
23952393

23962394
returns;
23972395
}
@@ -2460,8 +2458,7 @@ dequote_file_name(char *text, char quote_char)
24602458

24612459
length=strlen(text);
24622460
s=pg_malloc(length-2+1);
2463-
strncpy(s,text+1,length-2);
2464-
s[length]='\0';
2461+
strlcpy(s,text+1,length-2+1);
24652462

24662463
returns;
24672464
}

‎src/interfaces/ecpg/preproc/descriptor.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* functions needed for descriptor handling
33
*
4-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/descriptor.c,v 1.24 2006/03/11 04:38:40 momjian Exp $
4+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/descriptor.c,v 1.25 2007/02/07 00:52:35 petere Exp $
55
*
66
* since descriptor might be either a string constant or a string var
77
* we need to check for a constant if we expect a constant
@@ -323,7 +323,6 @@ descriptor_variable(const char *name, int input)
323323
{descriptor_names[1], (structECPGtype*)&descriptor_type,0,NULL}
324324
};
325325

326-
strncpy(descriptor_names[input],name,MAX_DESCRIPTOR_NAMELEN);
327-
descriptor_names[input][MAX_DESCRIPTOR_NAMELEN-1]=0;
326+
strlcpy(descriptor_names[input],name,sizeof(descriptor_names[input]));
328327
return (structvariable*)&varspace[input];
329328
}

‎src/test/regress/pg_regress.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.28 2007/02/01 19:10:30 momjian Exp $
14+
* $PostgreSQL: pgsql/src/test/regress/pg_regress.c,v 1.29 2007/02/07 00:52:35 petere Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -349,8 +349,7 @@ replace_string(char *string, char *replace, char *replacement)
349349
{
350350
char*dup=strdup(string);
351351

352-
strncpy(string,dup,ptr-string);
353-
string[ptr-string]=0;
352+
strlcpy(string,dup,ptr-string+1);
354353
strcat(string,replacement);
355354
strcat(string,dup+ (ptr-string)+strlen(replace));
356355
free(dup);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp