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

Commit71edbb6

Browse files
committed
Avoid use of non-portable strnlen() in pgstat_clip_activity().
The use of strnlen rather than strlen was just paranoia. Instead ofgiving up on the paranoia, just implement the safeguarddifferently. And add a comment explaining why we're careful.Author: Andres FreundDiscussion:https://postgr.es/m/E1duOkJ-0001Mc-U5@gemulon.postgresql.org
1 parent54b6cd5 commit71edbb6

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6288,10 +6288,24 @@ pgstat_db_requested(Oid databaseid)
62886288
* freed.
62896289
*/
62906290
char*
6291-
pgstat_clip_activity(constchar*activity)
6291+
pgstat_clip_activity(constchar*raw_activity)
62926292
{
6293-
intrawlen=strnlen(activity,pgstat_track_activity_query_size-1);
6294-
intcliplen;
6293+
char*activity;
6294+
intrawlen;
6295+
intcliplen;
6296+
6297+
/*
6298+
* Some callers, like pgstat_get_backend_current_activity(), do not
6299+
* guarantee that the buffer isn't concurrently modified. We try to take
6300+
* care that the buffer is always terminated by a NULL byte regardless,
6301+
* but let's still be paranoid about the string's length. In those cases
6302+
* the underlying buffer is guaranteed to be
6303+
* pgstat_track_activity_query_size large.
6304+
*/
6305+
activity=pnstrdup(raw_activity,pgstat_track_activity_query_size-1);
6306+
6307+
/* now double-guaranteed to be NULL terminated */
6308+
rawlen=strlen(activity);
62956309

62966310
/*
62976311
* All supported server-encodings make it possible to determine the length
@@ -6303,5 +6317,8 @@ pgstat_clip_activity(const char *activity)
63036317
*/
63046318
cliplen=pg_mbcliplen(activity,rawlen,
63056319
pgstat_track_activity_query_size-1);
6306-
returnpnstrdup(activity,cliplen);
6320+
6321+
activity[cliplen]='\0';
6322+
6323+
returnactivity;
63076324
}

‎src/include/pgstat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ extern PgStat_BackendFunctionEntry *find_funcstat_entry(Oid func_id);
11991199

12001200
externvoidpgstat_initstats(Relationrel);
12011201

1202-
externchar*pgstat_clip_activity(constchar*activity);
1202+
externchar*pgstat_clip_activity(constchar*raw_activity);
12031203

12041204
/* ----------
12051205
* pgstat_report_wait_start() -

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp