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

Commit1d45168

Browse files
committed
Fix some misuses of strncat().
1 parent9ba4065 commit1d45168

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

‎src/bin/pg_config/pg_config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
1919
*
20-
* $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.20 2006/06/06 22:41:09 momjian Exp $
20+
* $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.21 2006/09/27 16:19:42 tgl Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -213,7 +213,7 @@ show_pgxs(bool all)
213213
if (all)
214214
printf("PGXS = ");
215215
get_pkglib_path(mypath,path);
216-
strncat(path,"/pgxs/src/makefiles/pgxs.mk",MAXPGPATH-1);
216+
strncat(path,"/pgxs/src/makefiles/pgxs.mk",MAXPGPATH-1-strlen(path));
217217
cleanup_path(path);
218218
printf("%s\n",path);
219219
}

‎src/tutorial/funcs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/tutorial/funcs.c,v 1.15 2006/05/31 20:58:09 tgl Exp $ */
1+
/* $PostgreSQL: pgsql/src/tutorial/funcs.c,v 1.16 2006/09/27 16:19:42 tgl Exp $ */
22

33
/******************************************************************************
44
These are user-defined functions that can be bound to a Postgres backend
@@ -85,13 +85,14 @@ copytext(text *t)
8585
text*
8686
concat_text(text*arg1,text*arg2)
8787
{
88-
int32new_text_size=VARSIZE(arg1)+VARSIZE(arg2)-VARHDRSZ;
88+
int32arg1_size=VARSIZE(arg1)-VARHDRSZ;
89+
int32arg2_size=VARSIZE(arg2)-VARHDRSZ;
90+
int32new_text_size=arg1_size+arg2_size+VARHDRSZ;
8991
text*new_text= (text*)palloc(new_text_size);
9092

91-
memset((void*)new_text,0,new_text_size);
9293
VARATT_SIZEP(new_text)=new_text_size;
93-
strncpy(VARDATA(new_text),VARDATA(arg1),VARSIZE(arg1)-VARHDRSZ);
94-
strncat(VARDATA(new_text),VARDATA(arg2),VARSIZE(arg2)-VARHDRSZ);
94+
memcpy(VARDATA(new_text),VARDATA(arg1),arg1_size);
95+
memcpy(VARDATA(new_text)+arg1_size,VARDATA(arg2),arg2_size);
9596
returnnew_text;
9697
}
9798

‎src/tutorial/funcs_new.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/tutorial/funcs_new.c,v 1.11 2006/07/14 14:52:27 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/tutorial/funcs_new.c,v 1.12 2006/09/27 16:19:42 tgl Exp $ */
22

33
/******************************************************************************
44
These are user-defined functions that can be bound to a Postgres backend
@@ -101,13 +101,14 @@ concat_text(PG_FUNCTION_ARGS)
101101
{
102102
text*arg1=PG_GETARG_TEXT_P(0);
103103
text*arg2=PG_GETARG_TEXT_P(1);
104-
int32new_text_size=VARSIZE(arg1)+VARSIZE(arg2)-VARHDRSZ;
104+
int32arg1_size=VARSIZE(arg1)-VARHDRSZ;
105+
int32arg2_size=VARSIZE(arg2)-VARHDRSZ;
106+
int32new_text_size=arg1_size+arg2_size+VARHDRSZ;
105107
text*new_text= (text*)palloc(new_text_size);
106108

107-
memset((void*)new_text,0,new_text_size);
108109
VARATT_SIZEP(new_text)=new_text_size;
109-
strncpy(VARDATA(new_text),VARDATA(arg1),VARSIZE(arg1)-VARHDRSZ);
110-
strncat(VARDATA(new_text),VARDATA(arg2),VARSIZE(arg2)-VARHDRSZ);
110+
memcpy(VARDATA(new_text),VARDATA(arg1),arg1_size);
111+
memcpy(VARDATA(new_text)+arg1_size,VARDATA(arg2),arg2_size);
111112
PG_RETURN_TEXT_P(new_text);
112113
}
113114

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp