* Validates a user input bson as bytes to ensure it's compatible with the database. * This includes validating field names for the specified flags. */
| 500 | * This includes validating field names for the specified flags. |
| 501 | */ |
| 502 | void |
| 503 | ValidateInputBsonBytes(const uint8_t *documentBytes, |
| 504 | uint32_t documentBytesLength, |
| 505 | bson_validate_flags_t validateFlag) |
| 506 | { |
| 507 | bson_t bson; |
| 508 | if (!bson_init_static(&bson, documentBytes, documentBytesLength)) |
| 509 | { |
| 510 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 511 | errmsg( |
| 512 | "invalid input syntax for BSON: Unable to initialize for validate"))); |
| 513 | } |
| 514 | |
| 515 | bson_error_t error; |
| 516 | if (!bson_validate_with_error(&bson, validateFlag, &error)) |
| 517 | { |
| 518 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE), |
| 519 | errmsg("invalid input syntax for BSON. Code: %u, Message %s", |
| 520 | error.code, error.message))); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | |
| 525 | /* |
no outgoing calls
no test coverage detected