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

Commit4ed6dc7

Browse files
committed
Set snprintf.c's maximum number of NL arguments to be 31.
Previously, we used the platform's NL_ARGMAX if any, otherwise 16.The trouble with this is that the platform value is hugely variable,ranging from the POSIX-minimum 9 to as much as 64K on recent FreeBSD.Values of more than a dozen or two have no practical use and slow downthe initialization of the argtypes array. Worse, they cause snprintf.cto consume far more stack space than was the design intention, possiblyresulting in stack-overflow crashes.Standardize on 31, which is comfortably more than we need (it looks likeno existing translatable message has more than about 10 parameters).I chose that, not 32, to make the array sizes powers of 2, for somepossible small gain in speed of the memset.The lack of reported crashes suggests that the set of platforms weuse snprintf.c on (in released branches) may have no overlap withthe set where NL_ARGMAX has unreasonably large values. But that'snot entirely clear, so back-patch to all supported branches.Per report from Mateusz Guzik (via Thomas Munro).Discussion:https://postgr.es/m/CAEepm=3VF=PUp2f8gU8fgZB22yPE_KBS0+e1AHAtQ=09schTHg@mail.gmail.com
1 parent01c7a87 commit4ed6dc7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

‎src/port/snprintf.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@
4444
#endif
4545
#include<sys/param.h>
4646

47-
#ifndefNL_ARGMAX
48-
#defineNL_ARGMAX 16
49-
#endif
47+
/*
48+
* We used to use the platform's NL_ARGMAX here, but that's a bad idea,
49+
* first because the point of this module is to remove platform dependencies
50+
* not perpetuate them, and second because some platforms use ridiculously
51+
* large values, leading to excessive stack consumption in dopr().
52+
*/
53+
#definePG_NL_ARGMAX 31
5054

5155

5256
/*
@@ -345,8 +349,8 @@ dopr(PrintfTarget *target, const char *format, va_list args)
345349
doublefvalue;
346350
char*strvalue;
347351
inti;
348-
PrintfArgTypeargtypes[NL_ARGMAX+1];
349-
PrintfArgValueargvalues[NL_ARGMAX+1];
352+
PrintfArgTypeargtypes[PG_NL_ARGMAX+1];
353+
PrintfArgValueargvalues[PG_NL_ARGMAX+1];
350354

351355
/*
352356
* Parse the format string to determine whether there are %n$ format
@@ -396,7 +400,7 @@ dopr(PrintfTarget *target, const char *format, va_list args)
396400
gotonextch1;
397401
case'$':
398402
have_dollar= true;
399-
if (accum <=0||accum>NL_ARGMAX)
403+
if (accum <=0||accum>PG_NL_ARGMAX)
400404
gotobad_format;
401405
if (afterstar)
402406
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp