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

Commit625b38e

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 parent3d0f68d commit625b38e

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
@@ -41,9 +41,13 @@
4141
#endif
4242
#include<sys/param.h>
4343

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

4852

4953
/*
@@ -358,8 +362,8 @@ dopr(PrintfTarget *target, const char *format, va_list args)
358362
doublefvalue;
359363
char*strvalue;
360364
inti;
361-
PrintfArgTypeargtypes[NL_ARGMAX+1];
362-
PrintfArgValueargvalues[NL_ARGMAX+1];
365+
PrintfArgTypeargtypes[PG_NL_ARGMAX+1];
366+
PrintfArgValueargvalues[PG_NL_ARGMAX+1];
363367

364368
/*
365369
* Parse the format string to determine whether there are %n$ format
@@ -409,7 +413,7 @@ dopr(PrintfTarget *target, const char *format, va_list args)
409413
gotonextch1;
410414
case'$':
411415
have_dollar= true;
412-
if (accum <=0||accum>NL_ARGMAX)
416+
if (accum <=0||accum>PG_NL_ARGMAX)
413417
gotobad_format;
414418
if (afterstar)
415419
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp