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

Commit1cb63c7

Browse files
committed
Clean up code for widget_in() and widget_out().
Given syntactically wrong input, widget_in() could call atof() with anindeterminate pointer argument, typically leading to a crash; or if itdidn't do that, it might return a NULL pointer, which again would leadto a crash since old-style C functions aren't supposed to do thingsthat way. Fix that by correcting the off-by-one syntax test andthrowing a proper error rather than just returning NULL.Also, since widget_in and widget_out have been marked STRICT for along time, their tests for null inputs are just dead code; remove 'em.In the oldest branches, also improve widget_out to use snprintf notsprintf, just to be sure.In passing, get rid of a long-since-useless sprintf into a local bufferthat nothing further is done with, and make some other minor codingstyle cleanups.In the intended regression-testing usage of these functions, none ofthis is very significant; but if the regression test database wereleft around in a production installation, these bugs could amountto a minor security hazard.Piotr Stefaniak, Michael Paquier, and Tom Lane
1 parentb602842 commit1cb63c7

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

‎src/test/regress/regress.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,34 +249,33 @@ WIDGET *
249249
widget_in(char*str)
250250
{
251251
char*p,
252-
*coord[NARGS],
253-
buf2[1000];
252+
*coord[NARGS];
254253
inti;
255254
WIDGET*result;
256255

257-
if (str==NULL)
258-
returnNULL;
259256
for (i=0,p=str;*p&&i<NARGS&&*p!=RDELIM;p++)
260-
if (*p==','|| (*p==LDELIM&& !i))
257+
{
258+
if (*p==DELIM|| (*p==LDELIM&&i==0))
261259
coord[i++]=p+1;
262-
if (i<NARGS-1)
263-
returnNULL;
260+
}
261+
262+
if (i<NARGS)
263+
ereport(ERROR,
264+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
265+
errmsg("invalid input syntax for type widget: \"%s\"",
266+
str)));
267+
264268
result= (WIDGET*)palloc(sizeof(WIDGET));
265269
result->center.x=atof(coord[0]);
266270
result->center.y=atof(coord[1]);
267271
result->radius=atof(coord[2]);
268272

269-
snprintf(buf2,sizeof(buf2),"widget_in: read (%f, %f, %f)\n",
270-
result->center.x,result->center.y,result->radius);
271273
returnresult;
272274
}
273275

274276
char*
275277
widget_out(WIDGET*widget)
276278
{
277-
if (widget==NULL)
278-
returnNULL;
279-
280279
returnpsprintf("(%g,%g,%g)",
281280
widget->center.x,widget->center.y,widget->radius);
282281
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp