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

Commitd2b0b60

Browse files
committed
Improve our response to invalid format strings, and detect more cases.
Places that are testing for *printf failure ought to include the formatstring in their error reports, since bad-format-string is one of themore likely causes of such failure. This both makes it easier to findand repair the mistake, and provides at least some useful info to theuser who stumbles across such a problem.Also, tighten snprintf.c to report EINVAL for an invalid flag orfinal character in a format %-spec (including the case where the%-spec is missing a final character altogether). This seems likebetter project policy, and it also allows removing an instructionor two from the hot code path.Back-patch the error reporting change in pvsnprintf, since it should beharmless and may be helpful; but not the snprintf.c change.Per discussion of bug #15511 from Ertuğrul Kahveci, which reported aninvalid translated format string. These changes don't fix that error,but they should improve matters next time we make such a mistake.Discussion:https://postgr.es/m/15511-1d8b6a0bc874112f@postgresql.org
1 parent7a55ccc commitd2b0b60

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

‎src/backend/utils/misc/guc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4387,7 +4387,7 @@ static struct config_enum ConfigureNamesEnum[] =
43874387
},
43884388
&ssl_min_protocol_version,
43894389
PG_TLS1_VERSION,
4390-
ssl_protocol_versions_info+1/* don't allow PG_TLS_ANY */,
4390+
ssl_protocol_versions_info+1,/* don't allow PG_TLS_ANY */
43914391
NULL,NULL,NULL
43924392
},
43934393

@@ -9666,7 +9666,7 @@ do_serialize(char **destptr, Size *maxbytes, const char *fmt,...)
96669666
if (n<0)
96679667
{
96689668
/* Shouldn't happen. Better show errno description. */
9669-
elog(ERROR,"vsnprintf failed: %m");
9669+
elog(ERROR,"vsnprintf failed: %m with format string \"%s\"",fmt);
96709670
}
96719671
if (n >=*maxbytes)
96729672
{

‎src/common/psprintf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ pvsnprintf(char *buf, size_t len, const char *fmt, va_list args)
113113
if (unlikely(nprinted<0))
114114
{
115115
#ifndefFRONTEND
116-
elog(ERROR,"vsnprintf failed: %m");
116+
elog(ERROR,"vsnprintf failed: %m with format string \"%s\"",fmt);
117117
#else
118-
fprintf(stderr,"vsnprintf failed: %s\n",strerror(errno));
118+
fprintf(stderr,"vsnprintf failed: %m with format string \"%s\"\n",fmt);
119119
exit(EXIT_FAILURE);
120120
#endif
121121
}

‎src/port/snprintf.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,6 @@ dopr(PrintfTarget *target, const char *format, va_list args)
452452
have_star=afterstar= false;
453453
nextch2:
454454
ch=*format++;
455-
if (ch=='\0')
456-
break;/* illegal, but we don't complain */
457455
switch (ch)
458456
{
459457
case'-':
@@ -718,6 +716,13 @@ dopr(PrintfTarget *target, const char *format, va_list args)
718716
case'%':
719717
dopr_outch('%',target);
720718
break;
719+
default:
720+
721+
/*
722+
* Anything else --- in particular, '\0' indicating end of
723+
* format string --- is bogus.
724+
*/
725+
gotobad_format;
721726
}
722727

723728
/* Check for failure after each conversion spec */
@@ -782,8 +787,6 @@ find_arguments(const char *format, va_list args,
782787
afterstar= false;
783788
nextch1:
784789
ch=*format++;
785-
if (ch=='\0')
786-
break;/* illegal, but we don't complain */
787790
switch (ch)
788791
{
789792
case'-':
@@ -918,6 +921,8 @@ find_arguments(const char *format, va_list args,
918921
case'm':
919922
case'%':
920923
break;
924+
default:
925+
return false;/* bogus format string */
921926
}
922927

923928
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp