|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.63 2002/07/16 03:30:27 momjian Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/utils/adt/geo_ops.c,v 1.64 2002/08/29 23:05:44 momjian Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -269,11 +269,17 @@ path_decode(int opentype, int npts, char *str, int *isopen, char **ss, Point *p)
|
269 | 269 | static char *
|
270 | 270 | path_encode(bool closed, int npts, Point *pt)
|
271 | 271 | {
|
272 |
| - char *result = palloc(npts * (P_MAXLEN + 3) + 2); |
273 |
| - |
| 272 | + int size = npts * (P_MAXLEN + 3) + 2; |
| 273 | + char *result; |
274 | 274 | char *cp;
|
275 | 275 | int i;
|
276 | 276 |
|
| 277 | + /* Check for integer overflow */ |
| 278 | + if ((size - 2) / npts != (P_MAXLEN + 3)) |
| 279 | + elog(ERROR, "Too many points requested"); |
| 280 | + |
| 281 | + result = palloc(size); |
| 282 | + |
277 | 283 | cp = result;
|
278 | 284 | switch (closed)
|
279 | 285 | {
|
@@ -1230,7 +1236,7 @@ path_in(PG_FUNCTION_ARGS)
|
1230 | 1236 | depth++;
|
1231 | 1237 | }
|
1232 | 1238 |
|
1233 |
| - size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * npts; |
| 1239 | + size = offsetof(PATH, p[0]) + sizeof(path->p[0]) * npts; |
1234 | 1240 | path = (PATH *) palloc(size);
|
1235 | 1241 |
|
1236 | 1242 | path->size = size;
|
@@ -3596,13 +3602,21 @@ path_add(PG_FUNCTION_ARGS)
|
3596 | 3602 | PATH *p1 = PG_GETARG_PATH_P(0);
|
3597 | 3603 | PATH *p2 = PG_GETARG_PATH_P(1);
|
3598 | 3604 | PATH *result;
|
3599 |
| - int size; |
| 3605 | + int size, |
| 3606 | + base_size; |
3600 | 3607 | int i;
|
3601 | 3608 |
|
3602 | 3609 | if (p1->closed || p2->closed)
|
3603 | 3610 | PG_RETURN_NULL();
|
3604 | 3611 |
|
3605 |
| - size = offsetof(PATH, p[0]) +sizeof(p1->p[0]) * (p1->npts + p2->npts); |
| 3612 | + base_size = sizeof(p1->p[0]) * (p1->npts + p2->npts); |
| 3613 | + size = offsetof(PATH, p[0]) + base_size; |
| 3614 | + |
| 3615 | + /* Check for integer overflow */ |
| 3616 | + if (base_size / sizeof(p1->p[0]) != (p1->npts + p2->npts) || |
| 3617 | + size <= base_size) |
| 3618 | + elog(ERROR, "too many points requested."); |
| 3619 | + |
3606 | 3620 | result = (PATH *) palloc(size);
|
3607 | 3621 |
|
3608 | 3622 | result->size = size;
|
@@ -4413,17 +4427,24 @@ circle_poly(PG_FUNCTION_ARGS)
|
4413 | 4427 | int32 npts = PG_GETARG_INT32(0);
|
4414 | 4428 | CIRCLE *circle = PG_GETARG_CIRCLE_P(1);
|
4415 | 4429 | POLYGON *poly;
|
4416 |
| - int size; |
| 4430 | + int base_size, |
| 4431 | + size; |
4417 | 4432 | int i;
|
4418 | 4433 | double angle;
|
4419 | 4434 |
|
4420 | 4435 | if (FPzero(circle->radius) || (npts < 2))
|
4421 | 4436 | elog(ERROR, "Unable to convert circle to polygon");
|
4422 | 4437 |
|
4423 |
| - size = offsetof(POLYGON, p[0]) +(sizeof(poly->p[0]) * npts); |
| 4438 | + base_size = sizeof(poly->p[0]) * npts; |
| 4439 | + size = offsetof(POLYGON, p[0]) + base_size; |
| 4440 | + |
| 4441 | + /* Check for integer overflow */ |
| 4442 | + if (base_size / npts != sizeof(poly->p[0]) || size <= base_size) |
| 4443 | + elog(ERROR, "too many points requested"); |
| 4444 | + |
4424 | 4445 | poly = (POLYGON *) palloc(size);
|
4425 | 4446 |
|
4426 |
| - MemSet((char *) poly, 0, size); /* zero any holes */ |
| 4447 | + MemSet(poly, 0, size); /* zero any holes */ |
4427 | 4448 | poly->size = size;
|
4428 | 4449 | poly->npts = npts;
|
4429 | 4450 |
|
|
0 commit comments