@@ -58,11 +58,11 @@ ltree_in(PG_FUNCTION_ARGS)
58
58
ptr += charlen ;
59
59
}
60
60
61
- if (num + 1 > MaxAllocSize / sizeof ( nodeitem ) )
61
+ if (num + 1 > LTREE_MAX_LEVELS )
62
62
ereport (ERROR ,
63
63
(errcode (ERRCODE_PROGRAM_LIMIT_EXCEEDED ),
64
- errmsg ("number of levels (%d) exceeds the maximum allowed (%d)" ,
65
- num + 1 , ( int ) ( MaxAllocSize / sizeof ( nodeitem )) )));
64
+ errmsg ("number of ltree levels (%d) exceeds the maximum allowed (%d)" ,
65
+ num + 1 , LTREE_MAX_LEVELS )));
66
66
list = lptr = (nodeitem * ) palloc (sizeof (nodeitem ) * (num + 1 ));
67
67
ptr = buf ;
68
68
while (* ptr )
@@ -227,11 +227,11 @@ lquery_in(PG_FUNCTION_ARGS)
227
227
}
228
228
229
229
num ++ ;
230
- if (num > MaxAllocSize / ITEMSIZE )
230
+ if (num > LQUERY_MAX_LEVELS )
231
231
ereport (ERROR ,
232
232
(errcode (ERRCODE_PROGRAM_LIMIT_EXCEEDED ),
233
- errmsg ("number of levels (%d) exceeds the maximum allowed (%d)" ,
234
- num , ( int ) ( MaxAllocSize / ITEMSIZE ) )));
233
+ errmsg ("number of lquery levels (%d) exceeds the maximum allowed (%d)" ,
234
+ num , LQUERY_MAX_LEVELS )));
235
235
curqlevel = tmpql = (lquery_level * ) palloc0 (ITEMSIZE * num );
236
236
ptr = buf ;
237
237
while (* ptr )
@@ -344,7 +344,7 @@ lquery_in(PG_FUNCTION_ARGS)
344
344
else if (charlen == 1 && t_iseq (ptr , '.' ))
345
345
{
346
346
curqlevel -> low = 0 ;
347
- curqlevel -> high = 0xffff ;
347
+ curqlevel -> high = LTREE_MAX_LEVELS ;
348
348
curqlevel = NEXTLEV (curqlevel );
349
349
state = LQPRS_WAITLEVEL ;
350
350
}
@@ -357,7 +357,16 @@ lquery_in(PG_FUNCTION_ARGS)
357
357
state = LQPRS_WAITSNUM ;
358
358
else if (t_isdigit (ptr ))
359
359
{
360
- curqlevel -> low = atoi (ptr );
360
+ int low = atoi (ptr );
361
+
362
+ if (low < 0 || low > LTREE_MAX_LEVELS )
363
+ ereport (ERROR ,
364
+ (errcode (ERRCODE_SYNTAX_ERROR ),
365
+ errmsg ("lquery syntax error" ),
366
+ errdetail ("Low limit (%d) exceeds the maximum allowed (%d)." ,
367
+ low , LTREE_MAX_LEVELS )));
368
+
369
+ curqlevel -> low = (uint16 ) low ;
361
370
state = LQPRS_WAITND ;
362
371
}
363
372
else
@@ -367,12 +376,21 @@ lquery_in(PG_FUNCTION_ARGS)
367
376
{
368
377
if (t_isdigit (ptr ))
369
378
{
370
- curqlevel -> high = atoi (ptr );
379
+ int high = atoi (ptr );
380
+
381
+ if (high < 0 || high > LTREE_MAX_LEVELS )
382
+ ereport (ERROR ,
383
+ (errcode (ERRCODE_SYNTAX_ERROR ),
384
+ errmsg ("lquery syntax error" ),
385
+ errdetail ("High limit (%d) exceeds the maximum allowed (%d)." ,
386
+ high , LTREE_MAX_LEVELS )));
387
+
388
+ curqlevel -> high = (uint16 ) high ;
371
389
state = LQPRS_WAITCLOSE ;
372
390
}
373
391
else if (charlen == 1 && t_iseq (ptr , '}' ))
374
392
{
375
- curqlevel -> high = 0xffff ;
393
+ curqlevel -> high = LTREE_MAX_LEVELS ;
376
394
state = LQPRS_WAITEND ;
377
395
}
378
396
else
@@ -422,7 +440,7 @@ lquery_in(PG_FUNCTION_ARGS)
422
440
if (lptr -> start == ptr )
423
441
ereport (ERROR ,
424
442
(errcode (ERRCODE_SYNTAX_ERROR ),
425
- errmsg ("syntax error" ),
443
+ errmsg ("lquery syntax error" ),
426
444
errdetail ("Unexpected end of line." )));
427
445
428
446
lptr -> len = ptr - lptr -> start -
@@ -432,7 +450,7 @@ lquery_in(PG_FUNCTION_ARGS)
432
450
if (lptr -> len == 0 )
433
451
ereport (ERROR ,
434
452
(errcode (ERRCODE_SYNTAX_ERROR ),
435
- errmsg ("syntax error" ),
453
+ errmsg ("lquery syntax error" ),
436
454
errdetail ("Unexpected end of line." )));
437
455
438
456
if (lptr -> wlen > 255 )
@@ -444,11 +462,11 @@ lquery_in(PG_FUNCTION_ARGS)
444
462
lptr -> wlen , pos )));
445
463
}
446
464
else if (state == LQPRS_WAITOPEN )
447
- curqlevel -> high = 0xffff ;
465
+ curqlevel -> high = LTREE_MAX_LEVELS ;
448
466
else if (state != LQPRS_WAITEND )
449
467
ereport (ERROR ,
450
468
(errcode (ERRCODE_SYNTAX_ERROR ),
451
- errmsg ("syntax error" ),
469
+ errmsg ("lquery syntax error" ),
452
470
errdetail ("Unexpected end of line." )));
453
471
454
472
curqlevel = tmpql ;
@@ -468,8 +486,8 @@ lquery_in(PG_FUNCTION_ARGS)
468
486
else if (curqlevel -> low > curqlevel -> high )
469
487
ereport (ERROR ,
470
488
(errcode (ERRCODE_SYNTAX_ERROR ),
471
- errmsg ("syntax error" ),
472
- errdetail ("Low limit(%d) is greater than upper(%d)." ,
489
+ errmsg ("lquery syntax error" ),
490
+ errdetail ("Low limit (%d) is greater than upper (%d)." ,
473
491
curqlevel -> low , curqlevel -> high )));
474
492
475
493
curqlevel = NEXTLEV (curqlevel );
@@ -593,15 +611,15 @@ lquery_out(PG_FUNCTION_ARGS)
593
611
}
594
612
else if (curqlevel -> low == 0 )
595
613
{
596
- if (curqlevel -> high == 0xffff )
614
+ if (curqlevel -> high == LTREE_MAX_LEVELS )
597
615
{
598
616
* ptr = '*' ;
599
617
* (ptr + 1 ) = '\0' ;
600
618
}
601
619
else
602
620
sprintf (ptr , "*{,%d}" , curqlevel -> high );
603
621
}
604
- else if (curqlevel -> high == 0xffff )
622
+ else if (curqlevel -> high == LTREE_MAX_LEVELS )
605
623
{
606
624
sprintf (ptr , "*{%d,}" , curqlevel -> low );
607
625
}
0 commit comments