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

Commitacbdda4

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 parent831c22b commitacbdda4

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
@@ -237,34 +237,33 @@ WIDGET *
237237
widget_in(char*str)
238238
{
239239
char*p,
240-
*coord[NARGS],
241-
buf2[1000];
240+
*coord[NARGS];
242241
inti;
243242
WIDGET*result;
244243

245-
if (str==NULL)
246-
returnNULL;
247244
for (i=0,p=str;*p&&i<NARGS&&*p!=RDELIM;p++)
248-
if (*p==','|| (*p==LDELIM&& !i))
245+
{
246+
if (*p==DELIM|| (*p==LDELIM&&i==0))
249247
coord[i++]=p+1;
250-
if (i<NARGS-1)
251-
returnNULL;
248+
}
249+
250+
if (i<NARGS)
251+
ereport(ERROR,
252+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
253+
errmsg("invalid input syntax for type widget: \"%s\"",
254+
str)));
255+
252256
result= (WIDGET*)palloc(sizeof(WIDGET));
253257
result->center.x=atof(coord[0]);
254258
result->center.y=atof(coord[1]);
255259
result->radius=atof(coord[2]);
256260

257-
snprintf(buf2,sizeof(buf2),"widget_in: read (%f, %f, %f)\n",
258-
result->center.x,result->center.y,result->radius);
259261
returnresult;
260262
}
261263

262264
char*
263265
widget_out(WIDGET*widget)
264266
{
265-
if (widget==NULL)
266-
returnNULL;
267-
268267
returnpsprintf("(%g,%g,%g)",
269268
widget->center.x,widget->center.y,widget->radius);
270269
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp