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

Commit2f397a0

Browse files
committed
Clean up pg_basebackup libpq usage
When using libpq, it's generally preferrable to just use the stringswhich are in the PQ structures instead of copying them out, so dothat instead in BaseBackup(), eliminating the strcpy()'s used there.Also, in ReceiveAndUnpackTarFile(), check the string length for thedirectory returned by the server for the tablespace path.
1 parent3cb7a39 commit2f397a0

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,15 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
509509
if (PQgetisnull(res,rownum,0))
510510
strcpy(current_path,basedir);
511511
else
512+
{
513+
if (PQgetlength(res,rownum,1) >=MAXPGPATH)
514+
{
515+
fprintf(stderr,_("%s: received invalid directory (too long): %s"),
516+
progname,PQgetvalue(res,rownum,1));
517+
disconnect_and_exit(1);
518+
}
512519
strcpy(current_path,PQgetvalue(res,rownum,1));
520+
}
513521

514522
/*
515523
* Make sure we're unpacking into an empty directory
@@ -814,8 +822,6 @@ BaseBackup(void)
814822
charcurrent_path[MAXPGPATH];
815823
charescaped_label[MAXPGPATH];
816824
inti;
817-
charxlogstart[64];
818-
charxlogend[64];
819825
intminServerMajor,
820826
maxServerMajor;
821827
intserverMajor;
@@ -877,11 +883,9 @@ BaseBackup(void)
877883
progname);
878884
disconnect_and_exit(1);
879885
}
880-
strcpy(xlogstart,PQgetvalue(res,0,0));
881886
if (verbose&&includewal)
882-
fprintf(stderr,"xlog start point: %s\n",xlogstart);
887+
fprintf(stderr,"xlog start point: %s\n",PQgetvalue(res,0,0));
883888
PQclear(res);
884-
MemSet(xlogend,0,sizeof(xlogend));
885889

886890
/*
887891
* Get the header
@@ -962,9 +966,8 @@ BaseBackup(void)
962966
progname);
963967
disconnect_and_exit(1);
964968
}
965-
strcpy(xlogend,PQgetvalue(res,0,0));
966969
if (verbose&&includewal)
967-
fprintf(stderr,"xlog end point: %s\n",xlogend);
970+
fprintf(stderr,"xlog end point: %s\n",PQgetvalue(res,0,0));
968971
PQclear(res);
969972

970973
res=PQgetResult(conn);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp