SWE-Bench ProMax: sample task

swebench_promax · subset test · answered by GPT-6.1 Terra @ medium

One task from this benchmark exactly as the model saw it, everything the model did, and how it was graded.

Task

CESNET__libyang-c_8d3d805

System

You are a helpful assistant that can interact with a computer shell to solve programming tasks.

User

<pr_description>

Consider the following PR description:
During integration testing of YANG data validation across built-in type plugins, two distinct but related categories of defects were identified that collectively undermine consistent constraint enforcement.

First, several string-derived type plugins—including hex-string, date-and-time, ipv4-address-no-zone, ipv4-prefix, ipv6-address-no-zone, ipv6-prefix, xpath1.0, and others—contain inline logic within their storage routines that directly calls length-restriction and pattern-validation functions. This duplicates constraint checking that should instead be delegated to the framework's centralized validation pathway through dedicated validation callbacks. For the date-and-time type specifically, the storage function performs its own pattern matching against the date-and-time regular expression before handing the value to the time-parsing function ly_time_str2time. This means a malformed value such as "2005-05-31T23:15:15.-08:00" (which has a decimal point followed by no fractional digits) is caught by the pattern check and rejected with a pattern-unsatisfied error (LY_EVALID). The correct behavior is for the storage function to omit the inline pattern validation entirely and let ly_time_str2time detect the malformed input, which must produce an error code of LY_EINVAL with the exact error message "Missing date-and-time fractions after '.'." reported at the node path. Removing the redundant inline length and pattern checks from all affected type plugins ensures that constraint enforcement flows through the proper validation callbacks, eliminating fragmentation between the storage and validation layers.

Second, the validation callback implementations for core numeric and binary types—decimal64, signed integers, unsigned integers, binary, and string—declare function signatures that are missing a parameter required by the current plugin framework interface. The framework's validation callback contract now requires an additional parameter for extension instance context (a pointer to a top-level extension instance used for extension-aware validation). The existing forward declarations and definitions of these validation callbacks omit this parameter, causing compilation failures against updated framework headers and incorrect internal call sites where the storage function invokes its own validation callback without passing the additional argument. Each of these callbacks and their corresponding internal invocations must be updated to include the extension instance parameter in the correct position.

Additionally, the schema-mount extension plugin's identifier string as it appears in diagnostic log messages must be updated. Specifically, log output produced during extension validation currently renders the plugin name as "ly2 schema mount v1", but the correct identifier that must appear in log messages is "ly2 schema mount" (without the version suffix). Test infrastructure performs exact string matching on these log entries—for example, validating that a must-condition failure within a mounted schema produces a message prefixed with exactly "Ext plugin "ly2 schema mount":" —so the plugin's registered display name must match precisely.

Together, these changes restore a single consistent validation path: string-derived type plugins no longer duplicate constraint logic in their storage routines, core type validation callbacks conform to the framework's current signature contract including extension instance context, and the schema-mount extension's log identity is corrected to its canonical form.

</pr_description>

<instructions>

Task Instructions

Overview

You're a software engineer interacting continuously with a computer by submitting commands.
You'll be helping implement necessary changes to meet requirements in the PR description.
Your task is specifically to make changes to non-test files in the current directory in order to fix the issue described in the PR description in a way that is general and consistent with the codebase.
<IMPORTANT>This is an interactive process where you will think and issue AT LEAST ONE command, see the result, then think and issue your next command(s).</important>

For each response:

  1. Include a THOUGHT section explaining your reasoning and what you're trying to accomplish
  2. Provide one or more bash tool calls to execute

Important Boundaries

  • MODIFY: Regular source code files in /testbed (this is the working directory for all your subsequent commands)
  • DO NOT MODIFY: Tests, configuration files (pyproject.toml, setup.cfg, etc.)

Recommended Workflow

  1. Analyze the codebase by finding and reading relevant files
  2. Create a script to reproduce the issue
  3. Edit the source code to resolve the issue
  4. Verify your fix works by running your script again
  5. Test edge cases to ensure your fix is robust

Command Execution Rules

You are operating in an environment where

  1. You issue at least one command
  2. The system executes the command(s) in a subshell
  3. You see the result(s)
  4. You write your next command(s)

Each response should include:

  1. Reasoning text where you explain your analysis and plan
  2. At least one tool call with your command

CRITICAL REQUIREMENTS:

  • Your response SHOULD include reasoning text explaining what you're doing
  • Your response MUST include AT LEAST ONE bash tool call. You can make MULTIPLE tool calls in a single response when the commands are independent (e.g., searching multiple files, reading different parts of the codebase).
  • Directory or environment variable changes are not persistent. Every action is executed in a new subshell.
  • However, you can prefix any action with MY_ENV_VAR=MY_VALUE cd /path/to/working/dir && ... or write/load environment variables from files

Example of a CORRECT response:

<example_response>

I need to understand the Builder-related code. Let me find relevant files and check the project structure.

[Makes multiple bash tool calls: {"command": "ls -la"}, {"command": "find src -name '*.java' | grep -i builder"}, {"command": "cat README.md | head -50"}]

</example_response>

Environment Details

  • You have a full Linux shell environment
  • Always use non-interactive flags (-y, -f) for commands
  • Avoid interactive tools like vi, nano, or any that require user input
  • You can use bash commands or invoke any tool that is available in the environment
  • You can also create new tools or scripts to help you with the task
  • If a tool isn't available, you can also install it

Submission

When you've completed your work, you MUST submit your changes as a git patch.
Follow these steps IN ORDER, with SEPARATE commands:

Step 1: Create the patch file
Run git diff -- path/to/file1 path/to/file2 > patch.txt listing only the source files you modified.
Do NOT commit your changes.

<IMPORTANT>

The patch must only contain changes to the specific source files you modified to fix the issue.
Do not submit file creations or changes to any of the following files:

  • test and reproduction files
  • helper scripts, tests, or tools that you created
  • installation, build, packaging, configuration, or setup scripts unless they are directly part of the issue you were fixing (you can assume that the environment is already set up for your client)
  • binary or compiled files

</IMPORTANT>

Step 2: Verify your patch
Inspect patch.txt to confirm it only contains your intended changes and headers show --- a/ and +++ b/ paths.

Step 3: Submit (EXACT command required)
You MUST use this EXACT command to submit:

echo COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT && cat patch.txt

If the command fails (nonzero exit status), it will not submit.

<CRITICAL>

  • Creating/viewing the patch and submitting it MUST be separate commands (not combined with &&).
  • If you modify patch.txt after verifying, you SHOULD verify again before submitting.
  • You CANNOT continue working (reading, editing, testing) in any way on this task after submitting.

</CRITICAL>

</instructions>

Transcript

26 calls · 1,001,009 tokens
Turn 1evr/openai/gpt-6.1-terra@medium1,650 in · 139 out

Model

THOUGHT: I’ll locate the affected type plugins, their validation callback signatures, and the schema-mount registration before making targeted source changes.

▸bash{
{
  "command": "cd /testbed && git status --short && ls"
}
▸bash{
{
  "command": "cd /testbed && rg -n 'ly2 schema mount v1|lyplg_type_validate_(length|patterns)|lyplg_type_validate_.*\\(' src/plugins_types src/plugins_exts | head -200"
}
Turn 2evr/openai/gpt-6.1-terra@medium1,922 in · 217 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
?? build/
CMakeLists.txt
CMakeModules
CONTRIBUTING.md
Doxyfile.in
FindLibYANG.cmake
LICENSE
README.md
SECURITY.md
build
codecov.yml
compat
distro
doc
libyang.pc.in
modules
src
tests
tools
uncrustify.cfg
</output>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
bash: line 1: rg: command not found
</output>

Model

THOUGHT: The repository already has a build directory, and rg is unavailable. I’ll use grep to identify the relevant checks and callback definitions.

▸bash{
{
  "command": "cd /testbed && grep -R -nE 'ly2 schema mount v1|lyplg_type_validate_(length|patterns)' src | head -200"
}
▸bash{
{
  "command": "cd /testbed && ls src/plugins_types && grep -R -n 'lyplg_type_validate_' src/plugins_types/{decimal64,integer,unsigned,binary,string}.c 2>/dev/null | head -150"
}
▸bash{
{
  "command": "cd /testbed && grep -R -n 'Missing date-and-time fractions\\|ly_time_str2time' src | head -50"
}
Turn 3evr/openai/gpt-6.1-terra@medium4,081 in · 369 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
src/parser_common.c:116:        rc = lyplg_type_validate_patterns(ctx, patterns, value, strlen(value), &err);
src/plugins_types/date_and_time.c:118:    ret = lyplg_type_validate_patterns(type_dat->patterns, value, value_len, err);
src/plugins_types/hex_string.c:71:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/hex_string.c:110:        ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
src/plugins_types/instanceid_keys.c:170:    ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
src/plugins_types/ipv4_address_no_zone.c:103:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/ipv4_prefix.c:169:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/ipv4_prefix.c:173:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/string.c:145:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/xpath1.0.c:280:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types.c:541:lyplg_type_validate_patterns(const struct ly_ctx *ctx, struct lysc_pattern **patterns, const char *str, uint32_t str_len,
src/plugins_types.h:851:LIBYANG_API_DECL LY_ERR lyplg_type_validate_patterns(const struct ly_ctx *ctx, struct lysc_pattern **patterns,
src/xpath.c:4964:    rc = lyplg_type_validate_patterns(set->ctx, patterns, args[0]->val.str, strlen(args[0]->val.str), &err);
</output>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
binary.c
bits.c
boolean.c
date_and_time.c
decimal64.c
empty.c
enumeration.c
hex_string.c
identityref.c
instanceid.c
instanceid_keys.c
integer.c
ipv4_address.c
ipv4_address_no_zone.c
ipv4_prefix.c
ipv6_address.c
ipv6_address_no_zone.c
ipv6_prefix.c
leafref.c
lyds_tree.c
node_instanceid.c
string.c
time_period.c
union.c
xpath1.0.c
src/plugins_types/decimal64.c:37:static LY_ERR lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err);
src/plugins_types/decimal64.c:154:        ret = lyplg_type_validate_decimal64(ctx, type, NULL, NULL, storage, err);
src/plugins_types/decimal64.c:171: * @brief Implementation of ::lyplg_type_validate_clb for the built-in decimal64 type.
src/plugins_types/decimal64.c:174:lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
src/plugins_types/decimal64.c:187:        ret = lyplg_type_validate_range(type->basetype, type_dec->range, num, storage->_canonical,
src/plugins_types/decimal64.c:274:        .plugin.validate = lyplg_type_validate_decimal64,
src/plugins_types/integer.c:42:static LY_ERR lyplg_type_validate_int(const struct ly_ctx *ctx, const struct lysc_type *type,
src/plugins_types/integer.c:44:static LY_ERR lyplg_type_validate_uint(const struct ly_ctx *ctx, const struct lysc_type *type,
src/plugins_types/integer.c:158:        ret = lyplg_type_validate_int(ctx, type, NULL, NULL, storage, err);
src/plugins_types/integer.c:174: * @brief Implementation of ::lyplg_type_validate_clb for the signed interger types.
src/plugins_types/integer.c:177:lyplg_type_validate_int(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
src/plugins_types/integer.c:207:        ret = lyplg_type_validate_range(type->basetype, type_num->range, num, storage->_canonical,
src/plugins_types/integer.c:444:        ret = lyplg_type_validate_uint(ctx, type, NULL, NULL, storage, err);
src/plugins_types/integer.c:460: * @brief Implementation of ::lyplg_type_validate_clb for the unsigned interger types.
src/plugins_types/integer.c:463:lyplg_type_validate_uint(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
src/plugins_types/integer.c:493:        ret = lyplg_type_validate_range(type->basetype, type_num->range, num, storage->_canonical,
src/plugins_types/integer.c:650:        .plugin.validate = lyplg_type_validate_uint,
src/plugins_types/integer.c:664:        .plugin.validate = lyplg_type_validate_uint,
src/plugins_types/integer.c:678:        .plugin.validate = lyplg_type_validate_uint,
src/plugins_types/integer.c:692:        .plugin.validate = lyplg_type_validate_uint,
src/plugins_types/integer.c:706:        .plugin.validate = lyplg_type_validate_int,
src/plugins_types/integer.c:720:        .plugin.validate = lyplg_type_validate_int,
src/plugins_types/integer.c:734:        .plugin.validate = lyplg_type_validate_int,
src/plugins_types/integer.c:748:        .plugin.validate = lyplg_type_validate_int,
src/plugins_types/binary.c:48:static LY_ERR lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type,
src/plugins_types/binary.c:335:        ret = lyplg_type_validate_binary(ctx, type, NULL, NULL, storage, err);
src/plugins_types/binary.c:352: * @brief Implementation of ::lyplg_type_validate_clb for the binary type.
src/plugins_types/binary.c:355:lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
src/plugins_types/binary.c:372:        LY_CHECK_RET(lyplg_type_validate_range(LY_TYPE_BINARY, type_bin->length, val->size, value, value_len, err));
src/plugins_types/binary.c:514:        .plugin.validate = lyplg_type_validate_binary,
src/plugins_types/string.c:37:static LY_ERR lyplg_type_validate_string(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err);
src/plugins_types/string.c:105:        ret = lyplg_type_validate_string(ctx, type, NULL, NULL, storage, err);
src/plugins_types/string.c:121: * @brief Implementation of ::lyplg_type_validate_clb for the string type.
src/plugins_types/string.c:124:lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
src/plugins_types/string.c:140:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
src/plugins_types/string.c:145:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/string.c:167:        .plugin.validate = lyplg_type_validate_string,
</output>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
src/plugins_types/date_and_time.c:122:    ret = ly_time_str2time(value, &val->time, &val->fractions_s);
src/tree_data.h:2658:LIBYANG_API_DECL LY_ERR ly_time_str2time(const char *value, time_t *time, char **fractions_s);
src/tree_data_common.c:1654:ly_time_str2time(const char *value, time_t *time, char **fractions_s)
src/tree_data_common.c:1703:            LOGERR(NULL, LY_EINVAL, "Missing date-and-time fractions after '.'.");
src/tree_data_common.c:1800:    rc = ly_time_str2time(value, &ts->tv_sec, &fractions_s);
</output>

Model

THOUGHT: The code contains stale calls to the pattern API as well as outdated callback signatures. I’ll inspect how storage, centralized validation, and extension context are meant to interact before editing.

▸bash{
{
  "command": "cd /testbed && grep -n -A30 -B15 'typedef.*lyplg_type_validate_clb\\|lyplg_type_validate_clb)' src/plugins_types.h; grep -R -n 'schema mount v1\\|schema mount\"' src/plugins_exts* | head -50; grep -R -n 'lyplg_type_validate_range\\|lyplg_type_validate_patterns' src/plugins_types/*.c"
}
▸bash{
{
  "command": "cd /testbed && cat src/plugins_types/{hex_string,date_and_time,ipv4_address_no_zone,ipv4_prefix}.c",
  "max_output_chars": 40000
}
▸bash{
{
  "command": "cd /testbed && cat src/plugins_types/{ipv6_address_no_zone,ipv6_prefix,xpath1.0}.c",
  "max_output_chars": 40000
}
▸bash{
{
  "command": "cd /testbed && cat src/plugins_types/string.c && sed -n '20,200p' src/plugins_types/decimal64.c && sed -n '25,60p;140,185p;430,475p' src/plugins_types/integer.c && sed -n '35,60p;320,380p' src/plugins_types/binary.c",
  "max_output_chars": 30000
}
Turn 4evr/openai/gpt-6.1-terra@medium14,228 in · 359 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
556- *
557- * This callback is optional and may not be defined for types that do not require the accessible data tree for
558- * validation (::lyplg_type_store_clb fully stores and validates the value).
559- *
560- * @param[in] ctx libyang context.
561- * @param[in] type Original type of the value (not necessarily the stored one) being validated.
562- * @param[in] ctx_node Value data context node for validation.
563- * @param[in] tree External data tree (e.g. when validating RPC/Notification) with possibly referenced data.
564- * @param[in] top_ext Extension instance containing the definition of the data being created.
565- * @param[in,out] storage Storage of the value successfully filled by ::lyplg_type_store_clb. May be modified.
566- * @param[out] err Optionally provided error information in case of failure. If not provided to the caller, a generic
567- * error message is prepared instead. The error structure can be created by ::ly_err_new().
568- * @return LY_SUCCESS on success,
569- * @return LY_ERR value on error.
570- */
571:LIBYANG_API_DECL typedef LY_ERR (*lyplg_type_validate_clb)(const struct ly_ctx *ctx, const struct lysc_type *type,
572-        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,
573-        struct lyd_value *storage, struct ly_err_item **err);
574-
575-/**
576- * @brief Callback for comparing 2 values of the same type.
577- *
578- * It can be assumed that the same context (dictionary) was used for storing both values and the realtype
579- * member of both the values is the same.
580- *
581- * @param[in] ctx libyang context.
582- * @param[in] val1 First value to compare.
583- * @param[in] val2 Second value to compare.
584- * @return LY_SUCCESS if values are considered equal.
585- * @return LY_ENOT if values differ.
586- */
587-LIBYANG_API_DECL typedef LY_ERR (*lyplg_type_compare_clb)(const struct ly_ctx *ctx, const struct lyd_value *val1,
588-        const struct lyd_value *val2);
589-
590-/**
591- * @brief Callback for sorting values.
592- *
593- * It can be assumed that the same context (dictionary) was used for storing both values and the realtype
594- * member of both the values is the same.
595- *
596- * @param[in] ctx libyang context.
597- * @param[in] val1 First value to compare.
598- * @param[in] val2 Second value to compare.
599- * @return Negative number if val1 < val2,
600- * @return Zero if val1 == val2,
601- * @return Positive number if val1 > val2.
src/plugins_exts/schema_mount.c:1623:        .plugin.id = "ly2 schema mount",
src/plugins_types/binary.c:372:        LY_CHECK_RET(lyplg_type_validate_range(LY_TYPE_BINARY, type_bin->length, val->size, value, value_len, err));
src/plugins_types/date_and_time.c:113:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_dat->length, value_len, value, value_len, err);
src/plugins_types/date_and_time.c:118:    ret = lyplg_type_validate_patterns(type_dat->patterns, value, value_len, err);
src/plugins_types/decimal64.c:187:        ret = lyplg_type_validate_range(type->basetype, type_dec->range, num, storage->_canonical,
src/plugins_types/hex_string.c:66:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
src/plugins_types/hex_string.c:71:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/hex_string.c:104:            ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_size), value,
src/plugins_types/hex_string.c:110:        ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
src/plugins_types/instanceid_keys.c:165:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_size), value, value_size, err);
src/plugins_types/instanceid_keys.c:170:    ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
src/plugins_types/integer.c:207:        ret = lyplg_type_validate_range(type->basetype, type_num->range, num, storage->_canonical,
src/plugins_types/integer.c:493:        ret = lyplg_type_validate_range(type->basetype, type_num->range, num, storage->_canonical,
src/plugins_types/ipv4_address_no_zone.c:98:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
src/plugins_types/ipv4_address_no_zone.c:103:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/ipv4_prefix.c:169:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/ipv4_prefix.c:173:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/string.c:140:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
src/plugins_types/string.c:145:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/xpath1.0.c:275:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
src/plugins_types/xpath1.0.c:280:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
</output>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<warning>
The output of your last command was too long.
Please try a different command that produces less output.
If you're looking at a file you can try use head, tail or sed to view a smaller number of lines selectively.
If you're using grep or find and it produced too much output, you can use a more selective search pattern.
If you really need to see something from the full command's output, you can redirect output to a file and then search in that file.
</warning><output_head>
/**
 * @file hex_string.c
 * @author Michal Vasko <mvasko@cesnet.cz>
 * @brief Built-in hex-string and associated types plugin.
 *
 * Copyright (c) 2023 - 2025 CESNET, z.s.p.o.
 *
 * This source code is licensed under BSD 3-Clause License (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/BSD-3-Clause
 */

#define _GNU_SOURCE

#include "plugins_types.h"

#include <ctype.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "libyang.h"

/* additional internal headers for some useful simple macros */
#include "compat.h"
#include "ly_common.h"
#include "plugins_internal.h" /* LY_TYPE_*_STR */

/**
 * @page howtoDataLYB LYB Binary Format
 * @subsection howtoDataLYBTypesHexString phys-address, mac-address, hex-string, uuid (ietf-yang-types)
 *
 * | Size (b) | Mandatory | Type | Meaning |
 * | :------  | :-------: | :--: | :-----: |
 * | variable, full bytes | yes | `char *` | string itself |
 */

LIBYANG_API_DEF LY_ERR
lyplg_type_store_hex_string(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits,
        uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints,
        const struct lysc_node *UNUSED(ctx_node), const struct lysc_ext_instance *UNUSED(top_ext),
        struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
    uint32_t value_size, i;

    /* init storage */
    memset(storage, 0, sizeof *storage);
    storage->realtype = type;

    /* check value length */
    ret = lyplg_type_check_value_size("hex-string", format, value_size_bits, LYPLG_LYB_SIZE_VARIABLE_BYTES, 0,
            &value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* check hints */
    ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* length restriction of the string */
    if (type_str->length) {
        /* value_len is in bytes, but we need number of characters here */
        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

    /* pattern restrictions */
    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* make a copy, it is needed for canonization */
    if ((format != LY_VALUE_CANON) && !(options & LYPLG_TYPE_STORE_DYNAMIC)) {
        value = strndup(value, value_size);
        LY_CHECK_ERR_GOTO(!value, ret = LY_EMEM, cleanup);
        options |= LYPLG_TYPE_STORE_DYNAMIC;
    }

    /* store canonical value */
    if (format != LY_VALUE_CANON) {
        /* make lowercase and store, the value must be dynamic */
        for (i = 0; i < value_size; ++i) {
            ((char *)value)[i] = tolower(((char *)value)[i]);
        }

        ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
        options &= ~LYPLG_TYPE_STORE_DYNAMIC;
        LY_CHECK_GOTO(ret, cleanup);

        /* value may have been freed */
        value = storage->_canonical;
    } else {
        /* store directly */
        ret = lydict_insert(ctx, value_size ? value : "", value_size, &storage->_canonical);
        LY_CHECK_GOTO(ret, cleanup);
    }

    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
        /* validate length restriction of the string */
        if (type_str->length) {
            /* value_size is in bytes, but we need number of characters here */
            ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_size), value,
                    value_size, err);
            LY_CHECK_GOTO(ret, cleanup);
        }

        /* validate pattern restrictions */
        ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

cleanup:
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        free((void *)value);
    }

    if (ret) {
        lyplg_type_free_simple(ctx, storage);
    }
    return ret;
}

/**
 * @brief Plugin information for string type implementation.
 *
 * Note that external plugins are supposed to use:
 *
 *   LYPLG_TYPES = {
 */
const struct lyplg_type_record plugins_hex_string[] = {
    {
        .module = "ietf-yang-types",
        .revision = "2013-07-15",
        .name = "phys-address",

        .plugin.id = "ly2 hex-string",
        .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes,
        .plugin.store = lyplg_type_store_hex_string,
        .plugin.validate = NULL,
        .plugin.compare = lyplg_type_compare_simple,
        .plugin.sort = lyplg_type_sort_simple,
        .plugin.print = lyplg_type_print_simple,
        .plugin.duplicate = lyplg_type_dup_simple,
        .plugin.free = lyplg_type_free_simple,
 
</output_head>
<elided_chars>
27055 characters elided
</elided_chars>
<output_tail>
2ip(value, value_size, &val->addr, &val->prefix, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* zero host */
    ipv4prefix_zero_host(&val->addr, val->prefix);

    if (format == LY_VALUE_CANON) {
        /* store canonical value */
        if (options & LYPLG_TYPE_STORE_DYNAMIC) {
            ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
            options &= ~LYPLG_TYPE_STORE_DYNAMIC;
            LY_CHECK_GOTO(ret, cleanup);
        } else {
            ret = lydict_insert(ctx, value_size ? value : "", value_size, &storage->_canonical);
            LY_CHECK_GOTO(ret, cleanup);
        }
    }

cleanup:
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        free((void *)value);
    }

    if (ret) {
        lyplg_type_free_ipv4_prefix(ctx, storage);
    }
    return ret;
}

/**
 * @brief Implementation of ::lyplg_type_compare_clb for the ietf-inet-types ipv4-prefix type.
 */
static LY_ERR
lyplg_type_compare_ipv4_prefix(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
        const struct lyd_value *val2)
{
    struct lyd_value_ipv4_prefix *v1, *v2;

    LYD_VALUE_GET(val1, v1);
    LYD_VALUE_GET(val2, v2);

    if (memcmp(v1, v2, sizeof *v1)) {
        return LY_ENOT;
    }
    return LY_SUCCESS;
}

/**
 * @brief Implementation of ::lyplg_type_sort_clb for the ietf-inet-types ipv4-prefix type.
 */
static int
lyplg_type_sort_ipv4_prefix(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
        const struct lyd_value *val2)
{
    struct lyd_value_ipv4_prefix *v1, *v2;

    LYD_VALUE_GET(val1, v1);
    LYD_VALUE_GET(val2, v2);

    return memcmp(v1, v2, sizeof *v1);
}

/**
 * @brief Implementation of ::lyplg_type_compare_clb for the ietf-inet-types ipv4-prefix type.
 */
static const void *
lyplg_type_print_ipv4_prefix(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format,
        void *UNUSED(prefix_data), ly_bool *dynamic, uint32_t *value_size_bits)
{
    struct lyd_value_ipv4_prefix *val;
    char *ret;

    LYD_VALUE_GET(value, val);

    if (format == LY_VALUE_LYB) {
        *dynamic = 0;
        if (value_size_bits) {
            *value_size_bits = LYPLG_IPV4PREF_LYB_VALUE_SIZE;
        }
        return val;
    }

    /* generate canonical value if not already */
    if (!value->_canonical) {
        /* IPv4 mask + '/' + prefix */
        ret = malloc(INET_ADDRSTRLEN + 3);
        LY_CHECK_RET(!ret, NULL);

        /* convert back to string */
        if (!inet_ntop(AF_INET, &val->addr, ret, INET_ADDRSTRLEN)) {
            free(ret);
            return NULL;
        }

        /* add the prefix */
        sprintf(ret + strlen(ret), "/%" PRIu8, val->prefix);

        /* store it */
        if (lydict_insert_zc(ctx, ret, (const char **)&value->_canonical)) {
            LOGMEM(ctx);
            return NULL;
        }
    }

    /* use the cached canonical value */
    if (dynamic) {
        *dynamic = 0;
    }
    if (value_size_bits) {
        *value_size_bits = strlen(value->_canonical) * 8;
    }
    return value->_canonical;
}

/**
 * @brief Implementation of ::lyplg_type_dup_clb for the ietf-inet-types ipv4-prefix type.
 */
static LY_ERR
lyplg_type_dup_ipv4_prefix(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
{
    LY_ERR ret;
    struct lyd_value_ipv4_prefix *orig_val, *dup_val;

    memset(dup, 0, sizeof *dup);

    ret = lydict_insert(ctx, original->_canonical, 0, &dup->_canonical);
    LY_CHECK_GOTO(ret, error);

    LYPLG_TYPE_VAL_INLINE_PREPARE(dup, dup_val);
    LY_CHECK_ERR_GOTO(!dup_val, ret = LY_EMEM, error);

    LYD_VALUE_GET(original, orig_val);
    memcpy(dup_val, orig_val, sizeof *orig_val);

    dup->realtype = original->realtype;
    return LY_SUCCESS;

error:
    lyplg_type_free_ipv4_prefix(ctx, dup);
    return ret;
}

/**
 * @brief Implementation of ::lyplg_type_free_clb for the ietf-inet-types ipv4-prefix type.
 */
static void
lyplg_type_free_ipv4_prefix(const struct ly_ctx *ctx, struct lyd_value *value)
{
    struct lyd_value_ipv4_prefix *val;

    lydict_remove(ctx, value->_canonical);
    value->_canonical = NULL;
    LYD_VALUE_GET(value, val);
    LYPLG_TYPE_VAL_INLINE_DESTROY(val);
}

/**
 * @brief Plugin information for ipv4-prefix type implementation.
 *
 * Note that external plugins are supposed to use:
 *
 *   LYPLG_TYPES = {
 */
const struct lyplg_type_record plugins_ipv4_prefix[] = {
    {
        .module = "ietf-inet-types",
        .revision = "2013-07-15",
        .name = "ipv4-prefix",

        .plugin.id = "ly2 ipv4-prefix",
        .plugin.lyb_size = lyplg_type_lyb_size_ipv4_prefix,
        .plugin.store = lyplg_type_store_ipv4_prefix,
        .plugin.validate = NULL,
        .plugin.compare = lyplg_type_compare_ipv4_prefix,
        .plugin.sort = lyplg_type_sort_ipv4_prefix,
        .plugin.print = lyplg_type_print_ipv4_prefix,
        .plugin.duplicate = lyplg_type_dup_ipv4_prefix,
        .plugin.free = lyplg_type_free_ipv4_prefix,
    },
    {0}
};

</output_tail>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<warning>
The output of your last command was too long.
Please try a different command that produces less output.
If you're looking at a file you can try use head, tail or sed to view a smaller number of lines selectively.
If you're using grep or find and it produced too much output, you can use a more selective search pattern.
If you really need to see something from the full command's output, you can redirect output to a file and then search in that file.
</warning><output_head>
/**
 * @file ipv6_address_no_zone.c
 * @author Michal Vasko <mvasko@cesnet.cz>
 * @brief ietf-inet-types ipv6-address-no-zone type plugin.
 *
 * Copyright (c) 2019 - 2025 CESNET, z.s.p.o.
 *
 * This source code is licensed under BSD 3-Clause License (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/BSD-3-Clause
 */

#define _GNU_SOURCE /* strndup */

#include "plugins_internal.h"
#include "plugins_types.h"

#ifdef _WIN32
# include <winsock2.h>
# include <ws2tcpip.h>
#else
#  include <arpa/inet.h>
#  if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__)
#    include <netinet/in.h>
#    include <sys/socket.h>
#  endif
#endif
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "libyang.h"

#include "compat.h"
#include "ly_common.h"

/**
 * @page howtoDataLYB LYB Binary Format
 * @subsection howtoDataLYBTypesIPv6AddressNoZone ipv6-address-no-zone (ietf-inet-types)
 *
 * | Size (b) | Mandatory | Type | Meaning |
 * | :------  | :-------: | :--: | :-----: |
 * | 128       | yes       | `struct in6_addr *` | IPv6 address in network-byte order |
 */

static void lyplg_type_free_ipv6_address_no_zone(const struct ly_ctx *ctx, struct lyd_value *value);

/**
 * @brief Convert IP address to network-byte order.
 *
 * @param[in] value Value to convert.
 * @param[in] value_len Length of @p value.
 * @param[in] options Type store callback options.
 * @param[in,out] addr Allocated value for the address.
 * @param[out] err Error information on error.
 * @return LY_ERR value.
 */
static LY_ERR
ipv6addressnozone_str2ip(const char *value, uint32_t value_len, uint32_t options, struct in6_addr *addr, struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    const char *addr_str;
    char *addr_dyn = NULL;

    /* get the IP terminated with zero */
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        /* we can use the value directly */
        addr_str = value;
    } else {
        addr_dyn = strndup(value, value_len);
        addr_str = addr_dyn;
    }

    /* store the IPv6 address in network-byte order */
    if (!inet_pton(AF_INET6, addr_str, addr)) {
        ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to convert IPv6 address \"%s\".", addr_str);
        goto cleanup;
    }

cleanup:
    free(addr_dyn);
    return ret;
}

static void
lyplg_type_lyb_size_ipv6_address_no_zone(const struct lysc_type *UNUSED(type), enum lyplg_lyb_size_type *size_type,
        uint32_t *fixed_size_bits)
{
    *size_type = LYPLG_LYB_SIZE_FIXED_BITS;
    *fixed_size_bits = 128;
}

/**
 * @brief Implementation of ::lyplg_type_store_clb for the ipv6-address-no-zone ietf-inet-types type.
 */
static LY_ERR
lyplg_type_store_ipv6_address_no_zone(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value,
        uint32_t value_size_bits, uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints,
        const struct lysc_node *UNUSED(ctx_node), const struct lysc_ext_instance *UNUSED(top_ext),
        struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
    struct lyd_value_ipv6_address_no_zone *val;
    uint32_t value_size;

    /* init storage */
    memset(storage, 0, sizeof *storage);
    storage->realtype = type;

    /* check value length */
    ret = lyplg_type_check_value_size("ipv6-address-no-zone", format, value_size_bits, LYPLG_LYB_SIZE_FIXED_BITS, 128,
            &value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    if (format == LY_VALUE_LYB) {
        if ((options & LYPLG_TYPE_STORE_DYNAMIC) && LYPLG_TYPE_VAL_IS_DYN(val)) {
            /* use the value directly */
            storage->dyn_mem = (void *)value;
            options &= ~LYPLG_TYPE_STORE_DYNAMIC;
        } else {
            /* allocate value */
            LYPLG_TYPE_VAL_INLINE_PREPARE(storage, val);
            LY_CHECK_ERR_GOTO(!val, ret = LY_EMEM, cleanup);

            /* store IP address */
            memcpy(&val->addr, value, sizeof val->addr);
        }

        /* success */
        goto cleanup;
    }

    /* allocate value */
    LYPLG_TYPE_VAL_INLINE_PREPARE(storage, val);
    LY_CHECK_ERR_GOTO(!val, ret = LY_EMEM, cleanup);

    /* check hints */
    ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* get the network-byte order address, validates the value */
    ret = ipv6addressnozone_str2ip(value, value_size, options, &val->addr, err);
    LY_CHECK_GOTO(ret, cleanup);

    if (format == LY_VALUE_CANON) {
        /* store canonical value */
        if (options & LYPLG_TYPE_STORE_DYNAMIC) {
            ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
            options &= ~LYPLG_TYPE_S
</output_head>
<elided_chars>
29762 characters elided
</elided_chars>
<output_tail>
 lysc_ext_instance *UNUSED(top_ext),
        struct lyd_value *storage, struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    struct lyd_value_xpath10 *val;
    struct ly_set *set = NULL;
    uint32_t i;
    const char *pref, *uri;
    const struct ly_err_item *eitem;

    *err = NULL;
    LYD_VALUE_GET(storage, val);

    if (val->format != LY_VALUE_STR_NS) {
        /* nothing to validate */
        return LY_SUCCESS;
    }

    /* the XML namespace set must exist */
    assert(val->prefix_data);

    /* special handling of this particular node */
    assert(!strcmp(LYD_NAME(ctx_node), "parent-reference") &&
            !strcmp(ctx_node->schema->module->name, "ietf-yang-schema-mount"));

    /* get all the prefix mappings */
    if ((ret = lyd_find_xpath(ctx_node, "../../../namespace", &set))) {
        goto cleanup;
    }

    for (i = 0; i < set->count; ++i) {
        assert(!strcmp(LYD_NAME(lyd_child(set->dnodes[i])), "prefix"));
        pref = lyd_get_value(lyd_child(set->dnodes[i]));

        if (!lyd_child(set->dnodes[i])->next) {
            /* missing URI - invalid mapping, skip */
            continue;
        }
        assert(!strcmp(LYD_NAME(lyd_child(set->dnodes[i])->next), "uri"));
        uri = lyd_get_value(lyd_child(set->dnodes[i])->next);

        /* new NS */
        if ((ret = xpath10_add_ns(val->prefix_data, pref, uri))) {
            goto cleanup;
        }
    }

cleanup:
    ly_set_free(set, NULL);
    if (ret == LY_EMEM) {
        ly_err_new(err, LY_EMEM, LYVE_DATA, NULL, NULL, LY_EMEM_MSG);
    } else if (ret) {
        eitem = ly_err_last(LYD_CTX(ctx_node));
        ly_err_new(err, ret, LYVE_DATA, eitem->data_path, NULL, "%s", eitem->msg);
    }
    return ret;
}

LIBYANG_API_DEF const void *
lyplg_type_print_xpath10(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format,
        void *prefix_data, ly_bool *dynamic, uint32_t *value_size_bits)
{
    struct lyd_value_xpath10 *val;
    char *ret;
    struct ly_err_item *err = NULL;

    LYD_VALUE_GET(value, val);

    /* LY_VALUE_STR_NS should never be transformed */
    if ((val->format == LY_VALUE_STR_NS) || (format == LY_VALUE_CANON) || (format == LY_VALUE_JSON) ||
            (format == LY_VALUE_LYB)) {
        /* canonical */
        if (dynamic) {
            *dynamic = 0;
        }
        if (value_size_bits) {
            *value_size_bits = strlen(value->_canonical) * 8;
        }
        return value->_canonical;
    }

    /* print in the specific format */
    if (lyplg_type_print_xpath10_value(val, format, prefix_data, &ret, &err)) {
        if (err) {
            ly_err_print(ctx, err);
            ly_err_free(err);
        }
        return NULL;
    }

    *dynamic = 1;
    if (value_size_bits) {
        *value_size_bits = strlen(ret) * 8;
    }
    return ret;
}

LIBYANG_API_DEF LY_ERR
lyplg_type_dup_xpath10(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
{
    LY_ERR ret = LY_SUCCESS;
    struct lyd_value_xpath10 *orig_val, *dup_val;

    /* init dup value */
    memset(dup, 0, sizeof *dup);
    dup->realtype = original->realtype;

    ret = lydict_insert(ctx, original->_canonical, 0, &dup->_canonical);
    LY_CHECK_GOTO(ret, cleanup);

    LYPLG_TYPE_VAL_INLINE_PREPARE(dup, dup_val);
    LY_CHECK_ERR_GOTO(!dup_val, LOGMEM(ctx); ret = LY_EMEM, cleanup);
    dup_val->ctx = ctx;

    LYD_VALUE_GET(original, orig_val);
    ret = lyxp_expr_dup(ctx, orig_val->exp, 0, 0, &dup_val->exp);
    LY_CHECK_GOTO(ret, cleanup);

    ret = lyplg_type_prefix_data_dup(ctx, orig_val->format, orig_val->prefix_data, &dup_val->prefix_data);
    LY_CHECK_GOTO(ret, cleanup);
    dup_val->format = orig_val->format;

cleanup:
    if (ret) {
        lyplg_type_free_xpath10(ctx, dup);
    }
    return ret;
}

LIBYANG_API_DEF void
lyplg_type_free_xpath10(const struct ly_ctx *ctx, struct lyd_value *value)
{
    struct lyd_value_xpath10 *val;

    lydict_remove(ctx, value->_canonical);
    value->_canonical = NULL;
    LYD_VALUE_GET(value, val);
    if (val) {
        lyxp_expr_free(val->exp);
        lyplg_type_prefix_data_free(val->format, val->prefix_data);

        LYPLG_TYPE_VAL_INLINE_DESTROY(val);
    }
}

/**
 * @brief Plugin information for xpath1.0 type implementation.
 *
 * Note that external plugins are supposed to use:
 *
 *   LYPLG_TYPES = {
 */
const struct lyplg_type_record plugins_xpath10[] = {
    {
        .module = "ietf-yang-types",
        .revision = "2013-07-15",
        .name = "xpath1.0",

        .plugin.id = "ly2 xpath1.0",
        .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes,
        .plugin.store = lyplg_type_store_xpath10,
        .plugin.validate = lyplg_type_validate_xpath10,
        .plugin.compare = lyplg_type_compare_simple,
        .plugin.sort = lyplg_type_sort_simple,
        .plugin.print = lyplg_type_print_xpath10,
        .plugin.duplicate = lyplg_type_dup_xpath10,
        .plugin.free = lyplg_type_free_xpath10,
    },
    {0}
};

</output_tail>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<warning>
The output of your last command was too long.
Please try a different command that produces less output.
If you're looking at a file you can try use head, tail or sed to view a smaller number of lines selectively.
If you're using grep or find and it produced too much output, you can use a more selective search pattern.
If you really need to see something from the full command's output, you can redirect output to a file and then search in that file.
</warning><output_head>
/**
 * @file string.c
 * @author Radek Krejci <rkrejci@cesnet.cz>
 * @author Michal Vasko <mvasko@cesnet.cz>
 * @brief Built-in string type plugin.
 *
 * Copyright (c) 2019 - 2025 CESNET, z.s.p.o.
 *
 * This source code is licensed under BSD 3-Clause License (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/BSD-3-Clause
 */

#include "plugins_types.h"

#include <stdint.h>
#include <stdlib.h>

#include "libyang.h"

/* additional internal headers for some useful simple macros */
#include "compat.h"
#include "ly_common.h"
#include "plugins_internal.h" /* LY_TYPE_*_STR */

/**
 * @page howtoDataLYB LYB Binary Format
 * @subsection howtoDataLYBTypesString string (built-in)
 *
 * | Size (b) | Mandatory | Type | Meaning |
 * | :------  | :-------: | :--: | :-----: |
 * | variable, full bytes | yes | `char *` | string itself |
 */

static LY_ERR lyplg_type_validate_string(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err);

/**
 * @brief Check string value for invalid characters.
 *
 * @param[in] value String to check.
 * @param[in] value_size Size of @p value.
 * @param[out] err Generated error on error.
 * @return LY_ERR value.
 */
static LY_ERR
string_check_chars(const char *value, uint32_t value_size, struct ly_err_item **err)
{
    uint32_t len, parsed = 0;

    while (value_size - parsed) {
        if (ly_checkutf8(value + parsed, value_size - parsed, &len)) {
            return ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid character 0x%hhx.", value[parsed]);
        }
        parsed += len;
    }

    return LY_SUCCESS;
}

LIBYANG_API_DEF LY_ERR
lyplg_type_store_string(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits,
        uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints,
        const struct lysc_node *UNUSED(ctx_node), const struct lysc_ext_instance *UNUSED(top_ext),
        struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
    uint32_t value_size;

    /* init storage */
    memset(storage, 0, sizeof *storage);
    storage->realtype = type;

    /* check value length */
    ret = lyplg_type_check_value_size("string", format, value_size_bits, LYPLG_LYB_SIZE_VARIABLE_BYTES, 0, &value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    if (!(options & LYPLG_TYPE_STORE_IS_UTF8)) {
        /* check the UTF-8 encoding */
        ret = string_check_chars(value, value_size, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

    /* check hints */
    ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* store canonical value */
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
        options &= ~LYPLG_TYPE_STORE_DYNAMIC;
        LY_CHECK_GOTO(ret, cleanup);

        /* value may have been freed */
        value = storage->_canonical;
    } else {
        ret = lydict_insert(ctx, value_size ? value : "", value_size, &storage->_canonical);
        LY_CHECK_GOTO(ret, cleanup);
    }

    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
        /* validate value */
        ret = lyplg_type_validate_string(ctx, type, NULL, NULL, storage, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

cleanup:
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        free((void *)value);
    }

    if (ret) {
        lyplg_type_free_simple(ctx, storage);
    }
    return ret;
}

/**
 * @brief Implementation of ::lyplg_type_validate_clb for the string type.
 */
static LY_ERR
lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
{
    LY_ERR ret;
    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
    const void *value;
    size_t value_len;

    LY_CHECK_ARG_RET(NULL, type, storage, err, LY_EINVAL);
    value = lyd_value_get_canonical(ctx, storage);
    value_len = strlen(value);
    *err = NULL;

    /* length restriction of the string */
    if (type_str->length) {
        /* value_len is in bytes, but we need number of characters here */
        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
        LY_CHECK_RET(ret);
    }

    /* pattern restrictions */
    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
    LY_CHECK_RET(ret);

    return LY_SUCCESS;
}

/**
 * @brief Plugin information for string type implementation.
 *
 * Note 
</output_head>
<elided_chars>
9198 characters elided
</elided_chars>
<output_tail>
     free((void *)value);
    }

    if (ret) {
        lyplg_type_free_simple(ctx, storage);
    }
    return ret;
}

/**
 * @brief Implementation of ::lyplg_type_validate_clb for the signed interger types.
 */
static LY_ERR
lyplg_type_validate_int(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
{
    LY_ERR ret;
    struct lysc_type_num *type_num = (struct lysc_type_num *)type;
    int64_t num;

    LY_CHECK_ARG_RET(NULL, type, storage, err, LY_EINVAL);
    *err = NULL;
            ret = lydict_insert(ctx, value, value_size, &storage->_canonical);
            LY_CHECK_GOTO(ret, cleanup);
        }
    } else {
        /* generate canonical value */
        LY_CHECK_ERR_GOTO(asprintf(&canon, "%" PRIu64, num) == -1, ret = LY_EMEM, cleanup);

        /* store it */
        ret = lydict_insert_zc(ctx, canon, (const char **)&storage->_canonical);
        LY_CHECK_GOTO(ret, cleanup);
    }

    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
        /* validate value */
        ret = lyplg_type_validate_uint(ctx, type, NULL, NULL, storage, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

cleanup:
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        free((void *)value);
    }

    if (ret) {
        lyplg_type_free_simple(ctx, storage);
    }
    return ret;
}

/**
 * @brief Implementation of ::lyplg_type_validate_clb for the unsigned interger types.
 */
static LY_ERR
lyplg_type_validate_uint(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
{
    LY_ERR ret;
    struct lysc_type_num *type_num = (struct lysc_type_num *)type;
    uint64_t num;

    LY_CHECK_ARG_RET(NULL, type, storage, err, LY_EINVAL);
    *err = NULL;

    /* set the value (matters for big-endian) and get the correct int64 number */
    switch (type->basetype) {
    case LY_TYPE_UINT8:
 *
 * | Size (b) | Mandatory | Type | Meaning |
 * | :------  | :-------: | :--: | :-----: |
 * | variable, full bytes | yes | `void *` | value in binary |
 */

/**
 * @brief base64 encode table
 */
static const char b64_etable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";


static void lyplg_type_free_binary(const struct ly_ctx *ctx, struct lyd_value *value);
static LY_ERR lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type,
        const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err);

/**
 * @brief Encode binary value into a base64 string value.
 *
 * Reference https://tools.ietf.org/html/rfc4648#section-4
 *
 * @param[in] ctx libyang context.
 * @param[in] data Binary data value.
 * @param[in] size Size of @p data.
 * @param[out] str Encoded base64 string.
 * @param[out] str_len Length of returned @p str.
    /* store canonical value */
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
        options &= ~LYPLG_TYPE_STORE_DYNAMIC;
        LY_CHECK_GOTO(ret, cleanup);

        /* value may have been freed */
        value = storage->_canonical;
    } else {
        ret = lydict_insert(ctx, value_size ? value : "", value_size, &storage->_canonical);
        LY_CHECK_GOTO(ret, cleanup);
    }

    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
        /* validate value */
        ret = lyplg_type_validate_binary(ctx, type, NULL, NULL, storage, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

cleanup:
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        free((void *)value);
    }

    if (ret) {
        lyplg_type_free_binary(ctx, storage);
    }
    return ret;
}

static LY_ERR
/**
 * @brief Implementation of ::lyplg_type_validate_clb for the binary type.
 */
static LY_ERR
lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
{
    struct lysc_type_bin *type_bin = (struct lysc_type_bin *)type;
    struct lyd_value_binary *val;
    const void *value;
    size_t value_len;

    LY_CHECK_ARG_RET(NULL, type, storage, err, LY_EINVAL);

    val = LYPLG_TYPE_VAL_IS_DYN(val) ? (struct lyd_value_binary *)(storage->dyn_mem) : (struct lyd_value_binary *)(storage->fixed_mem);
    value = lyd_value_get_canonical(ctx, storage);
    value_len = strlen(value);
    *err = NULL;

    /* length restriction of the binary value */
    if (type_bin->length) {
        LY_CHECK_RET(lyplg_type_validate_range(LY_TYPE_BINARY, type_bin->length, val->size, value, value_len, err));
    }

    return LY_SUCCESS;
}

static LY_ERR
lyplg_type_compare_binary(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
{

</output_tail>

Model

THOUGHT: Schema-mount already registers the requested canonical identifier. I’ll check the framework’s generic restriction validation and remove only redundant derived-type checks, preserving the valid dedicated callbacks.

▸bash{
{
  "command": "cd /testbed && grep -R -n 'type_validate.*restr\\|validate.*restriction\\|plugins_string\\|lyplg_type_validate_patterns' src/{tree_data*,validation.c,plugins_types.c,plugins_internal.h} | head -120; grep -n 'type_str\\|type_dat\\|value_len\\|validate_patterns\\|validate_range' src/plugins_types/{date_and_time,hex_string,ipv4_address_no_zone,ipv4_prefix,ipv6_address_no_zone,ipv6_prefix,xpath1.0,string}.c"
}
▸bash{
{
  "command": "cd /testbed && sed -n '70,150p' src/plugins_types/date_and_time.c; sed -n '130,190p' src/plugins_types/ipv4_prefix.c; sed -n '225,300p' src/plugins_types/xpath1.0.c; sed -n '140,185p' src/plugins_types/instanceid_keys.c; grep -n 'schema.mount\\|plugin.id' src/plugins_exts/schema_mount.c | tail -20"
}
▸bash{
{
  "command": "cd /testbed && cmake --build build -j4 2>&1 | head -100",
  "timeout": 120000
}
Turn 5evr/openai/gpt-6.1-terra@medium19,898 in · 309 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
src/validation.c:1749:    /* validate all restrictions of nodes themselves */
src/validation.c:1808:    /* validate schema-based restrictions */
src/plugins_types.c:541:lyplg_type_validate_patterns(const struct ly_ctx *ctx, struct lysc_pattern **patterns, const char *str, uint32_t str_len,
src/plugins_types/date_and_time.c:56:    struct lysc_type_str *type_dat = (struct lysc_type_str *)type;
src/plugins_types/date_and_time.c:112:    if (type_dat->length) {
src/plugins_types/date_and_time.c:113:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_dat->length, value_len, value, value_len, err);
src/plugins_types/date_and_time.c:118:    ret = lyplg_type_validate_patterns(type_dat->patterns, value, value_len, err);
src/plugins_types/hex_string.c:47:    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
src/plugins_types/hex_string.c:64:    if (type_str->length) {
src/plugins_types/hex_string.c:65:        /* value_len is in bytes, but we need number of characters here */
src/plugins_types/hex_string.c:66:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
src/plugins_types/hex_string.c:71:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/hex_string.c:102:        if (type_str->length) {
src/plugins_types/hex_string.c:104:            ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_size), value,
src/plugins_types/hex_string.c:110:        ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
src/plugins_types/ipv4_address_no_zone.c:68:    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
src/plugins_types/ipv4_address_no_zone.c:96:    if (type_str->length) {
src/plugins_types/ipv4_address_no_zone.c:97:        /* value_len is in bytes, but we need number of characters here */
src/plugins_types/ipv4_address_no_zone.c:98:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
src/plugins_types/ipv4_address_no_zone.c:103:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/ipv4_prefix.c:66: * @param[in] value_len Length of @p value.
src/plugins_types/ipv4_prefix.c:73:ipv4prefix_str2ip(const char *value, uint32_t value_len, struct in_addr *addr, uint8_t *prefix, struct ly_err_item **err)
src/plugins_types/ipv4_prefix.c:80:    pref_str = ly_strnchr(value, '/', value_len);
src/plugins_types/ipv4_prefix.c:81:    ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix);
src/plugins_types/ipv4_prefix.c:131:    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
src/plugins_types/ipv4_prefix.c:169:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/ipv4_prefix.c:173:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/ipv6_address_no_zone.c:56: * @param[in] value_len Length of @p value.
src/plugins_types/ipv6_address_no_zone.c:63:ipv6addressnozone_str2ip(const char *value, uint32_t value_len, uint32_t options, struct in6_addr *addr, struct ly_err_item **err)
src/plugins_types/ipv6_address_no_zone.c:74:        addr_dyn = strndup(value, value_len);
src/plugins_types/ipv6_address_no_zone.c:107:    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
src/plugins_types/ipv6_prefix.c:58: * @param[in] value_len Length of @p value.
src/plugins_types/ipv6_prefix.c:65:ipv6prefix_str2ip(const char *value, uint32_t value_len, struct in6_addr *addr, uint8_t *prefix, struct ly_err_item **err)
src/plugins_types/ipv6_prefix.c:72:    pref_str = ly_strnchr(value, '/', value_len);
src/plugins_types/ipv6_prefix.c:73:    ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix);
src/plugins_types/ipv6_prefix.c:133:    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
src/plugins_types/xpath1.0.c:253:    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
src/plugins_types/xpath1.0.c:273:    if (type_str->length) {
src/plugins_types/xpath1.0.c:274:        /* value_len is in bytes, but we need number of characters here */
src/plugins_types/xpath1.0.c:275:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
src/plugins_types/xpath1.0.c:280:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
src/plugins_types/string.c:69:    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
src/plugins_types/string.c:128:    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
src/plugins_types/string.c:130:    size_t value_len;
src/plugins_types/string.c:134:    value_len = strlen(value);
src/plugins_types/string.c:138:    if (type_str->length) {
src/plugins_types/string.c:139:        /* value_len is in bytes, but we need number of characters here */
src/plugins_types/string.c:140:        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
src/plugins_types/string.c:145:    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
</output>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<warning>
The output of your last command was too long.
Please try a different command that produces less output.
If you're looking at a file you can try use head, tail or sed to view a smaller number of lines selectively.
If you're using grep or find and it produced too much output, you can use a more selective search pattern.
If you really need to see something from the full command's output, you can redirect output to a file and then search in that file.
</warning><output_head>
            ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid LYB date-and-time value size %" PRIu32
                    " b (expected at least 64 b).", value_size_bits);
            goto cleanup;
        }
        value_size = LYPLG_BITS2BYTES(value_size_bits);
        for (i = 9; i < value_size; ++i) {
            c = ((char *)value)[i];
            if (!isdigit(c)) {
                ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid LYB date-and-time character '%c' "
                        "(expected a digit).", c);
                goto cleanup;
            }
        }

        /* store timestamp */
        memcpy(&val->time, value, sizeof val->time);

        /* store fractions of second */
        if (value_size > 9) {
            val->fractions_s = strndup(((char *)value) + 9, value_size - 9);
            LY_CHECK_ERR_GOTO(!val->fractions_s, ret = LY_EMEM, cleanup);
        }

        /* store unknown timezone */
        if (value_size > 8) {
            val->unknown_tz = *(((uint8_t *)value) + 8) ? 1 : 0;
        }

        /* success */
        goto cleanup;
    }

    /* get value byte length */
    ret = lyplg_type_check_value_size("date-and-time", format, value_size_bits, LYPLG_LYB_SIZE_VARIABLE_BYTES, 0,
            &value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* check hints */
    ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* length restriction, there can be only ASCII chars */
    if (type_dat->length) {
        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_dat->length, value_len, value, value_len, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

    /* date-and-time pattern */
    ret = lyplg_type_validate_patterns(type_dat->patterns, value, value_len, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* convert to UNIX time and fractions of second */
    ret = ly_time_str2time(value, &val->time, &val->fractions_s);
    if (ret) {
        ret = ly_err_new(err, ret, 0, NULL, NULL, "%s", ly_last_logmsg());
        goto cleanup;
    }

    if (!strncmp(((char *)value + value_size) - 6, "-00:00", 6)) {
        /* unknown timezone */
        val->unknown_tz = 1;
    }

    if (format == LY_VALUE_CANON) {
        /* store canonical value */
        if (options & LYPLG_TYPE_STORE_DYNAMIC) {
            ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
            options &= ~LYPLG_TYPE_STORE_DYNAMIC;
            LY_CHECK_GOTO(ret, cleanup);
        } else {
            ret = lydict_insert(ctx, value, value_size, &storage->_canonical);
            LY_CHECK_GOTO(ret, cleanup);
        }
    }

cleanup:
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        free((void *)value);
    }

    if (ret) {
    LY_ERR ret = LY_SUCCESS;
    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
    struct lyd_value_ipv4_prefix *val;
    uint32_t value_size;

    /* init storage */
    memset(storage, 0, sizeof *storage);
    LYPLG_TYPE_VAL_INLINE_PREPARE(storage, val);
    LY_CHECK_ERR_GOTO(!val, ret = LY_EMEM, cleanup);
    storage->realtype = type;

    /* check value length */
    ret = lyplg_type_check_value_size("ipv4-prefix", format, value_size_bits, LYPLG_LYB_SIZE_FIXED_BITS,
            LYPLG_IPV4PREF_LYB_VALUE_SIZE, &value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    if (format == LY_VALUE_LYB) {
        /* validation */
        if (((uint8_t *)value)[4] > 32) {
            ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid LYB ipv4-prefix prefix length %" PRIu8 ".",
                    ((uint8_t *)value)[4]);
            goto cleanup;
        }

        /* store addr + prefix */
        memcpy(val, value, value_size);

        /* zero host */
        ipv4prefix_zero_host(&val->addr, val->prefix);

        /* success */
        goto cleanup;
    }

    /* check hints */
    ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* pattern restrictions */
    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* pattern restrictions */
    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* get the mask in network-byte order */
    ret = ipv4prefix_str2ip(value, value_size, &val->addr, &val->prefix, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* zero host */
    ipv4prefix_zero_host(&val->addr, val->prefix);

    if (format == LY_VALUE_CANON) {
        /* store canonical value */
        if (options & LYPLG_TYPE_STORE_DYNAMIC) {
            ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
            options &= ~LYPLG_TYPE_STORE_DYNAMIC;
            LY_CHECK_GOTO(ret, cleanup);
        } else {
            ret = lydict_insert(ctx, value_size ? value : "", value_size, &storage->_canonical);
    if (format == LY_VALUE_XML) {
      
</output_head>
<elided_chars>
1248 characters elided
</elided_chars>
<output_tail>
rage->realtype = type;

    /* check value length */
    ret = lyplg_type_check_value_size("xpath1.0", format, value_size_bits, LYPLG_LYB_SIZE_VARIABLE_BYTES, 0,
            &value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* check hints */
    ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* length restriction of the string */
    if (type_str->length) {
        /* value_len is in bytes, but we need number of characters here */
        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

    /* pattern restrictions */
    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* parse */
    ret = lyxp_expr_parse(ctx, value_size ? value : "", value_size, 1, &val->exp);
    LY_CHECK_GOTO(ret, cleanup);
    val->ctx = ctx;

    if (ctx_node && !strcmp(ctx_node->name, "parent-reference") && !strcmp(ctx_node->module->name, "ietf-yang-schema-mount")) {
        /* special case, this type uses prefix-namespace mapping provided directly in data, keep empty for now */
        val->format = format = LY_VALUE_STR_NS;
        ret = ly_set_new((struct ly_set **)&val->prefix_data);
        LY_CHECK_GOTO(ret, cleanup);
    } else {
        /* store format-specific data and context for later prefix resolution */
        ret = lyplg_type_prefix_data_new(ctx, value, value_size, format, prefix_data, &val->format, &val->prefix_data);
        LY_CHECK_GOTO(ret, cleanup);
    }

    switch (format) {
    case LY_VALUE_CANON:
    LY_ERR ret = LY_SUCCESS;
    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
    struct lyd_value_instance_identifier_keys *val;
    uint32_t value_size, *prev_lo, temp_lo = LY_LOSTORE;
    const struct ly_err_item *eitem;
    char *canon;

    /* init storage */
    memset(storage, 0, sizeof *storage);
    LYPLG_TYPE_VAL_INLINE_PREPARE(storage, val);
    LY_CHECK_ERR_GOTO(!val, ret = LY_EMEM, cleanup);
    storage->realtype = type;

    /* check value length */
    ret = lyplg_type_check_value_size("instance-identifier-keys", format, value_size_bits,
            LYPLG_LYB_SIZE_VARIABLE_BYTES, 0, &value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* check hints */
    ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* length restriction of the string */
    if (type_str->length) {
        /* value_size is in bytes, but we need number of characters here */
        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_size), value, value_size, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

    /* pattern restrictions */
    ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* parse instance-identifier keys, with optional prefix even though it should be mandatory */
    if (value_size && (((char *)value)[0] != '[')) {
        ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid first character '%c', list key predicates expected.",
                ((char *)value)[0]);
        goto cleanup;
    }

    /* do not log */
    prev_lo = ly_temp_log_options(&temp_lo);
    ret = ly_path_parse_predicate(ctx, NULL, value_size ? value : "", value_size, LY_PATH_PREFIX_OPTIONAL,
            LY_PATH_PRED_KEYS, &val->keys);
    ly_temp_log_options(prev_lo);
    if (ret) {
1458:                        schema_mount_sprinter_tree_cnode_override_mounted);
1464:                    schema_mount_sprinter_tree_pnode_override_mounted);
1468:                        schema_mount_sprinter_tree_pnode_override_mounted);
1473:                        schema_mount_sprinter_tree_pnode_override_mounted);
1494:            rc = lyplg_ext_sprinter_ctree_add_nodes(ctx, tree1, schema_mount_sprinter_tree_node_override_parent_refs);
1504:    rc = lyplg_ext_sprinter_tree_set_priv(ctx, st_priv, schema_mount_spriter_tree_free);
1516:schema_mount_compiled_size(const struct lysc_ext_instance *ext, struct ly_ht *addr_ht)
1548:schema_mount_compiled_print(const struct lysc_ext_instance *orig_ext, struct lysc_ext_instance *ext,
1617:const struct lyplg_ext_record plugins_schema_mount[] = {
1619:        .module = "ietf-yang-schema-mount",
1623:        .plugin.id = "ly2 schema mount",
1624:        .plugin.parse = schema_mount_parse,
1625:        .plugin.compile = schema_mount_compile,
1627:        .plugin.printer_ctree = schema_mount_sprinter_ctree,
1628:        .plugin.printer_ptree = schema_mount_sprinter_ptree,
1630:        .plugin.snode = schema_mount_snode,
1631:        .plugin.validate = schema_mount_validate,
1633:        .plugin.cfree = schema_mount_cfree,
1634:        .plugin.compiled_size = schema_mount_compiled_size,
1635:        .plugin.compiled_print = schema_mount_compiled_print,

</output_tail>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
Consolidate compiler generated dependencies of target fuzz_regression_test
[  1%] Built target fuzz_regression_test
Consolidate compiler generated dependencies of target yangobj
[  3%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/binary.c.o
[  3%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/decimal64.c.o
[  4%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/leafref.c.o
[  4%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/lyds_tree.c.o
/testbed/src/plugins_types/decimal64.c:173:1: warning: ‘static’ is not at beginning of declaration [-Wold-style-declaration]
  173 | static LY_ERR
      | ^~~~~~
/testbed/src/plugins_types/decimal64.c:173:1: error: duplicate ‘static’
/testbed/src/plugins_types/decimal64.c:174:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘lyplg_type_validate_decimal64’
  174 | lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/testbed/src/plugins_types/decimal64.c:274:28: warning: initialization of ‘LY_ERR (*)(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, const struct lysc_ext_instance *, struct lyd_value *, struct ly_err_item **)’ from incompatible pointer type ‘LY_ERR (*)(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, struct lyd_value *, struct ly_err_item **)’ [-Wincompatible-pointer-types]
  274 |         .plugin.validate = lyplg_type_validate_decimal64,
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/testbed/src/plugins_types/decimal64.c:274:28: note: (near initialization for ‘plugins_decimal64[0].plugin.validate’)
/testbed/src/plugins_types/decimal64.c:37:15: warning: ‘lyplg_type_validate_decimal64’ used but never defined
   37 | static LY_ERR lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gmake[2]: *** [CMakeFiles/yangobj.dir/build.make:832: CMakeFiles/yangobj.dir/src/plugins_types/decimal64.c.o] Error 1
gmake[2]: *** Waiting for unfinished jobs....
/testbed/src/plugins_types/binary.c:354:1: warning: ‘static’ is not at beginning of declaration [-Wold-style-declaration]
  354 | static LY_ERR
      | ^~~~~~
/testbed/src/plugins_types/binary.c:354:1: error: duplicate ‘static’
/testbed/src/plugins_types/binary.c:355:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘lyplg_type_validate_binary’
  355 | lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
/testbed/src/plugins_types/binary.c:514:28: warning: initialization of ‘LY_ERR (*)(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, const struct lysc_ext_instance *, struct lyd_value *, struct ly_err_item **)’ from incompatible pointer type ‘LY_ERR (*)(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, struct lyd_value *, struct ly_err_item **)’ [-Wincompatible-pointer-types]
  514 |         .plugin.validate = lyplg_type_validate_binary,
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~
/testbed/src/plugins_types/binary.c:514:28: note: (near initialization for ‘plugins_binary[0].plugin.validate’)
/testbed/src/plugins_types/binary.c:48:15: warning: ‘lyplg_type_validate_binary’ used but never defined
   48 | static LY_ERR lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~
gmake[2]: *** [CMakeFiles/yangobj.dir/build.make:790: CMakeFiles/yangobj.dir/src/plugins_types/binary.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:396: CMakeFiles/yangobj.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
</output>

Model

THOUGHT: The initial build also exposes duplicated static LY_ERR declarations. The address-prefix parsers relied on pattern checks for safe input, so I’ll inspect them and retain intrinsic parsing safeguards when removing those checks.

▸bash{
{
  "command": "cd /testbed && sed -n '60,115p' src/plugins_types/{ipv4_prefix,ipv6_prefix}.c; sed -n '50,140p' src/plugins_types/ipv4_address_no_zone.c; sed -n '1654,1725p' src/tree_data_common.c; grep -n -B2 -A6 'Implementation of ::lyplg_type_validate_clb' src/plugins_types/{decimal64,integer,binary,string}.c"
}
▸bash{
{
  "command": "cd /testbed && grep -R -n 'plugin.validate\\|basetype.*plugin\\|LY_TYPE_STRING.*validate' src/tree_data* src/validation.c src/plugins_types.c | head -100; grep -n 'plugin.validate\\|plugin.store' src/plugins_types/instanceid_keys.c src/plugins_types/hex_string.c; grep -n 'ly_strntou8' src/*.[ch] | head -20"
}
Turn 6evr/openai/gpt-6.1-terra@medium23,335 in · 184 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<warning>
The output of your last command was too long.
Please try a different command that produces less output.
If you're looking at a file you can try use head, tail or sed to view a smaller number of lines selectively.
If you're using grep or find and it produced too much output, you can use a more selective search pattern.
If you really need to see something from the full command's output, you can redirect output to a file and then search in that file.
</warning><output_head>
}

/**
 * @brief Convert IP address with a prefix in string to a binary network-byte order value.
 *
 * @param[in] value String to convert.
 * @param[in] value_len Length of @p value.
 * @param[in,out] addr Allocated address value to fill.
 * @param[out] prefix Prefix length.
 * @param[out] err Error information on error.
 * @return LY_ERR value.
 */
static LY_ERR
ipv4prefix_str2ip(const char *value, uint32_t value_len, struct in_addr *addr, uint8_t *prefix, struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    const char *pref_str;
    char *mask_str = NULL;

    /* it passed the pattern validation */
    pref_str = ly_strnchr(value, '/', value_len);
    ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix);

    /* get just the network prefix */
    mask_str = strndup(value, pref_str - value);
    LY_CHECK_ERR_GOTO(!mask_str, ret = LY_EMEM, cleanup);

    /* convert it to netword-byte order */
    if (inet_pton(AF_INET, mask_str, addr) != 1) {
        ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to convert IPv4 address \"%s\".", mask_str);
        goto cleanup;
    }

cleanup:
    free(mask_str);
    return ret;
}

/**
 * @brief Zero host-portion of the IP address.
 *
 * @param[in,out] addr IP address.
 * @param[in] prefix Prefix length.
 */
static void
ipv4prefix_zero_host(struct in_addr *addr, uint8_t prefix)
{
    uint32_t i, mask;

    /* zero host bits */
    mask = 0;
    for (i = 0; i < 32; ++i) {
        mask <<= 1;
        if (prefix > i) {
            mask |= 1;
        }
static void
lyplg_type_lyb_size_ipv4_address_no_zone(const struct lysc_type *UNUSED(type), enum lyplg_lyb_size_type *size_type,
        uint32_t *fixed_size_bits)
{
    *size_type = LYPLG_LYB_SIZE_FIXED_BITS;
    *fixed_size_bits = 32;
}

/**
 * @brief Implementation of ::lyplg_type_store_clb for the ipv4-address-no-zone ietf-inet-types type.
 */
static LY_ERR
lyplg_type_store_ipv4_address_no_zone(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value,
        uint32_t value_size_bits, uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints,
        const struct lysc_node *UNUSED(ctx_node), const struct lysc_ext_instance *UNUSED(top_ext),
        struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
    struct lyd_value_ipv4_address_no_zone *val;
    uint32_t value_size;

    /* init storage */
    memset(storage, 0, sizeof *storage);
    LYPLG_TYPE_VAL_INLINE_PREPARE(storage, val);
    LY_CHECK_ERR_GOTO(!val, ret = LY_EMEM, cleanup);
    storage->realtype = type;

    /* check value length */
    ret = lyplg_type_check_value_size("ipv4-address-no-zone", format, value_size_bits, LYPLG_LYB_SIZE_FIXED_BITS, 32,
            &value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    if (format == LY_VALUE_LYB) {
        /* store IP address */
        memcpy(&val->addr, value, 4);

        /* success */
        goto cleanup;
    }

    /* check hints */
    ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* length restriction of the string */
    if (type_str->length) {
        /* value_len is in bytes, but we need number of characters here */
        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

    /* pattern restrictions */
    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* we always need a dynamic value */
    if (!(options & LYPLG_TYPE_STORE_DYNAMIC)) {
        value = strndup(value, value_size);
        LY_CHECK_ERR_GOTO(!value, ret = LY_EMEM, cleanup);

        options |= LYPLG_TYPE_STORE_DYNAMIC;
    }

    /* get the network-byte order address */
    if (!inet_pton(AF_INET, value, &val->addr)) {
        ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to convert IPv4 address \"%s\".", (char *)value);
        goto cleanup;
    }

    /* store canonical value */
    ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
    options &= ~LYPLG_TYPE_STORE_DYNAMIC;
    LY_CHECK_GOTO(ret, cleanup);

cleanup:
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        free((void *)value);
    }

    if (ret) {
        lyplg_type_free_simple(ctx, storage);
    }
    return ret;
}

/**
 * @brief Implementation of ::lyplg_type_compare_clb for the ipv4-address-no-zone ietf-inet-types type.
 */
static LY_ERR
lyplg_type_compare_ipv4_address_no_zone(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
ly_time_str2time(const char *value, time_t *time, char **fractions_s)
{
    struct tm tm = {0};
    uint32_t i, frac_len;
    const char *frac;
    char *ptr;
    int64_t shift, shift_m;
    time_t t;

    LY_CHECK_ARG_RET(NULL, value
</output_head>
<elided_chars>
273 characters elided
</elided_chars>
<output_tail>
icit checks for some gross errors */
    if (tm.tm_mon > 11) {
        LOGERR(NULL, LY_EINVAL, "Invalid date-and-time month \"%d\".", tm.tm_mon);
        return LY_EINVAL;
    }
    if ((tm.tm_mday < 1) || (tm.tm_mday > 31)) {
        LOGERR(NULL, LY_EINVAL, "Invalid date-and-time day of month \"%d\".", tm.tm_mday);
        return LY_EINVAL;
    }
    if (tm.tm_hour > 23) {
        LOGERR(NULL, LY_EINVAL, "Invalid date-and-time hours \"%d\".", tm.tm_hour);
        return LY_EINVAL;
    }
    if (tm.tm_min > 59) {
        LOGERR(NULL, LY_EINVAL, "Invalid date-and-time minutes \"%d\".", tm.tm_min);
        return LY_EINVAL;
    }
    if (tm.tm_sec > 60) {
        LOGERR(NULL, LY_EINVAL, "Invalid date-and-time seconds \"%d\".", tm.tm_sec);
        return LY_EINVAL;
    }

    t = timegm(&tm);
    i = 19;

    /* fractions of a second */
    if (value[i] == '.') {
        ++i;
        frac = &value[i];
        for (frac_len = 0; isdigit(frac[frac_len]); ++frac_len) {}
        if (!frac_len) {
            LOGERR(NULL, LY_EINVAL, "Missing date-and-time fractions after '.'.");
            return LY_EINVAL;
        }

        i += frac_len;
    } else {
        frac = NULL;
    }

    /* apply offset */
    if ((value[i] == 'Z') || (value[i] == 'z')) {
        /* zero shift */
        shift = 0;
    } else {
        value += i;
        shift = strtol(value, &ptr, 10);
        if ((shift > 23) || (shift < -23)) {
            LOGERR(NULL, LY_EINVAL, "Invalid date-and-time timezone hour \"%" PRIi64 "\".", shift);
            return LY_EINVAL;
        } else if (ptr[0] != ':') {
            LOGERR(NULL, LY_EINVAL, "Invalid date-and-time timezone hour \"%s\".", value);
            return LY_EINVAL;
        }
src/plugins_types/decimal64.c-169-static LY_ERR
src/plugins_types/decimal64.c-170-/**
src/plugins_types/decimal64.c:171: * @brief Implementation of ::lyplg_type_validate_clb for the built-in decimal64 type.
src/plugins_types/decimal64.c-172- */
src/plugins_types/decimal64.c-173-static LY_ERR
src/plugins_types/decimal64.c-174-lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
src/plugins_types/decimal64.c-175-        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
src/plugins_types/decimal64.c-176-{
src/plugins_types/decimal64.c-177-    LY_ERR ret;
--
src/plugins_types/integer.c-172-
src/plugins_types/integer.c-173-/**
src/plugins_types/integer.c:174: * @brief Implementation of ::lyplg_type_validate_clb for the signed interger types.
src/plugins_types/integer.c-175- */
src/plugins_types/integer.c-176-static LY_ERR
src/plugins_types/integer.c-177-lyplg_type_validate_int(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
src/plugins_types/integer.c-178-        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
src/plugins_types/integer.c-179-{
src/plugins_types/integer.c-180-    LY_ERR ret;
--
src/plugins_types/integer.c-458-
src/plugins_types/integer.c-459-/**
src/plugins_types/integer.c:460: * @brief Implementation of ::lyplg_type_validate_clb for the unsigned interger types.
src/plugins_types/integer.c-461- */
src/plugins_types/integer.c-462-static LY_ERR
src/plugins_types/integer.c-463-lyplg_type_validate_uint(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
src/plugins_types/integer.c-464-        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
src/plugins_types/integer.c-465-{
src/plugins_types/integer.c-466-    LY_ERR ret;
--
src/plugins_types/binary.c-350-static LY_ERR
src/plugins_types/binary.c-351-/**
src/plugins_types/binary.c:352: * @brief Implementation of ::lyplg_type_validate_clb for the binary type.
src/plugins_types/binary.c-353- */
src/plugins_types/binary.c-354-static LY_ERR
src/plugins_types/binary.c-355-lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
src/plugins_types/binary.c-356-        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
src/plugins_types/binary.c-357-{
src/plugins_types/binary.c-358-    struct lysc_type_bin *type_bin = (struct lysc_type_bin *)type;
--
src/plugins_types/string.c-119-
src/plugins_types/string.c-120-/**
src/plugins_types/string.c:121: * @brief Implementation of ::lyplg_type_validate_clb for the string type.
src/plugins_types/string.c-122- */
src/plugins_types/string.c-123-static LY_ERR
src/plugins_types/string.c-124-lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
src/plugins_types/string.c-125-        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
src/plugins_types/string.c-126-{
src/plugins_types/string.c-127-    LY_ERR ret;

</output_tail>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
src/plugins_types/instanceid_keys.c:250:        .plugin.store = lyplg_type_store_instanceid_keys,
src/plugins_types/instanceid_keys.c:251:        .plugin.validate = NULL,
src/plugins_types/hex_string.c:140:        .plugin.store = lyplg_type_store_hex_string,
src/plugins_types/hex_string.c:141:        .plugin.validate = NULL,
src/plugins_types/hex_string.c:155:        .plugin.store = lyplg_type_store_hex_string,
src/plugins_types/hex_string.c:156:        .plugin.validate = NULL,
src/plugins_types/hex_string.c:170:        .plugin.store = lyplg_type_store_hex_string,
src/plugins_types/hex_string.c:171:        .plugin.validate = NULL,
src/plugins_types/hex_string.c:185:        .plugin.store = lyplg_type_store_hex_string,
src/plugins_types/hex_string.c:186:        .plugin.validate = NULL,
src/ly_common.c:600:ly_strntou8(const char *nptr, size_t len, uint8_t *ret)
src/ly_common.h:604:LY_ERR ly_strntou8(const char *nptr, size_t len, uint8_t *ret);
</output>

Model

THOUGHT: Removing the old IPv4 prefix checks requires explicit delimiter and numeric bounds validation to avoid invalid memory access. I’ll update the callback ABI and storage code, keeping the existing valid hex-string and instance-identifier-keys validation paths intact.

▸bash{
{
  "command": "cd /testbed && sed -n '590,630p' src/ly_common.c && sed -n '60,100p' src/plugins_types/ipv6_prefix.c && sed -n '35,52p' src/plugins_types/integer.c && sed -n '1654,1678p' src/tree_data_common.c && grep -R -n -- '->plugin->validate\\|->plugin.validate' src | head -70"
}
Turn 7evr/openai/gpt-6.1-terra@medium24,669 in · 1,170 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
    int rc = strncmp(refstr, str, str_len);

    if (!rc && (refstr[str_len] == '\0')) {
        return 0;
    } else {
        return rc ? rc : 1;
    }
}

LY_ERR
ly_strntou8(const char *nptr, size_t len, uint8_t *ret)
{
    uint8_t num = 0, dig;
    uint16_t dec_pow;

    if (len > 3) {
        /* overflow for sure */
        return LY_EDENIED;
    }

    dec_pow = 1;
    for ( ; len && isdigit(nptr[len - 1]); --len) {
        dig = nptr[len - 1] - 48;

        if (LY_OVERFLOW_MUL(UINT8_MAX, dig, dec_pow)) {
            return LY_EDENIED;
        }
        dig *= dec_pow;

        if (LY_OVERFLOW_ADD(UINT8_MAX, num, dig)) {
            return LY_EDENIED;
        }
        num += dig;

        dec_pow *= 10;
    }

    if (len) {
        return LY_EVALID;
    }
    *ret = num;
 * @param[out] prefix Prefix length.
 * @param[out] err Error information on error.
 * @return LY_ERR value.
 */
static LY_ERR
ipv6prefix_str2ip(const char *value, uint32_t value_len, struct in6_addr *addr, uint8_t *prefix, struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    const char *pref_str;
    char *mask_str = NULL;

    /* it passed the pattern validation */
    pref_str = ly_strnchr(value, '/', value_len);
    ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix);

    /* get just the network prefix */
    mask_str = strndup(value, pref_str - value);
    LY_CHECK_ERR_GOTO(!mask_str, ret = LY_EMEM, cleanup);

    /* convert it to netword-byte order */
    if (inet_pton(AF_INET6, mask_str, addr) != 1) {
        ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Failed to convert IPv6 address \"%s\".", mask_str);
        goto cleanup;
    }

cleanup:
    free(mask_str);
    return ret;
}

/**
 * @brief Zero host-portion of the IP address.
 *
 * @param[in,out] addr IP address.
 * @param[in] prefix Prefix length.
 */
static void
ipv6prefix_zero_host(struct in6_addr *addr, uint8_t prefix)
{
    uint32_t i, j, mask;

 * @subsection howtoDataLYBTypesInteger (u)int(8/16/32/64) (built-in)
 *
 * | Size (b) | Mandatory | Type | Meaning |
 * | :------  | :-------: | :--: | :-----: |
 * | variable | yes | pointer to the specific integer type | little-endian integer value |
 */

static LY_ERR lyplg_type_validate_int(const struct ly_ctx *ctx, const struct lysc_type *type,
        const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err);
static LY_ERR lyplg_type_validate_uint(const struct ly_ctx *ctx, const struct lysc_type *type,
        const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err);

static LY_ERR
lyplg_type_store_int(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits,
        uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints,
        const struct lysc_node *UNUSED(ctx_node), const struct lysc_ext_instance *UNUSED(top_ext),
        struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
{
ly_time_str2time(const char *value, time_t *time, char **fractions_s)
{
    struct tm tm = {0};
    uint32_t i, frac_len;
    const char *frac;
    char *ptr;
    int64_t shift, shift_m;
    time_t t;

    LY_CHECK_ARG_RET(NULL, value, strnlen(value, 18) > 17, time, LY_EINVAL);

    tm.tm_year = atoi(&value[0]) - 1900;
    tm.tm_mon = atoi(&value[5]) - 1;
    tm.tm_mday = atoi(&value[8]);
    tm.tm_hour = atoi(&value[11]);
    tm.tm_min = atoi(&value[14]);
    tm.tm_sec = atoi(&value[17]);

    /* explicit checks for some gross errors */
    if (tm.tm_mon > 11) {
        LOGERR(NULL, LY_EINVAL, "Invalid date-and-time month \"%d\".", tm.tm_mon);
        return LY_EINVAL;
    }
    if ((tm.tm_mday < 1) || (tm.tm_mday > 31)) {
        LOGERR(NULL, LY_EINVAL, "Invalid date-and-time day of month \"%d\".", tm.tm_mday);
</output>

Model

THOUGHT: I’ve identified the exact edits, including preserving hex-string’s existing conditional validation and adding safe prefix parsing for both IP families. I’ll apply them now and rebuild.

▸bash{
{
  "command": "cd /testbed && python3 - <<'PY'\nfrom pathlib import Path\nbase=Path('src/plugins_types')\nfor name in ['decimal64.c','integer.c','binary.c','string.c']:\n p=base/name; s=p.read_text()\n s=s.replace('const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)', 'const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext),\\n        struct lyd_value *storage, struct ly_err_item **err)')\n s=s.replace('const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err);', 'const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,\\n        struct lyd_value *storage, struct ly_err_item **err);')\n for func in ['decimal64','int','uint','binary','string']:\n  s=s.replace(f'lyplg_type_validate_{func}(ctx, type, NULL, NULL, storage, err)',f'lyplg_type_validate_{func}(ctx, type, NULL, NULL, NULL, storage, err)')\n s=s.replace('static LY_ERR\\n/**\\n * @brief Implementation of ::lyplg_type_validate_clb', '/**\\n * @brief Implementation of ::lyplg_type_validate_clb')\n if name=='string.c':\n  s=s.replace('    struct lysc_type_str *type_str = (struct lysc_type_str *)type;\\n    uint32_t value_size;', '    uint32_t value_size;')\n  s=s.replace('lyplg_type_validate_patterns(type_str->patterns, value, value_len, err)', 'lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_len, err)')\n p.write_text(s)\nfor name in ['hex_string.c','date_and_time.c','ipv4_address_no_zone.c','ipv4_prefix.c','ipv6_address_no_zone.c','ipv6_prefix.c','xpath1.0.c']:\n p=base/name; s=p.read_text()\n if name!='hex_string.c':\n  s=s.replace('    struct lysc_type_str *type_str = (struct lysc_type_str *)type;\\n','').replace('    struct lysc_type_str *type_dat = (struct lysc_type_str *)type;\\n','')\n start='    /* length restriction of the string */\\n'\n if name in ['hex_string.c','ipv4_address_no_zone.c','xpath1.0.c']:\n  a=s.index(start); b=s.index('    LY_CHECK_GOTO(ret, cleanup);', s.index('    /* pattern restrictions */',a))+len('    LY_CHECK_GOTO(ret, cleanup);\\n\\n'); s=s[:a]+s[b:]\n if name=='date_and_time.c':\n  a=s.index('    /* length restriction, there can be only ASCII chars */'); b=s.index('    /* convert to UNIX time',a); s=s[:a]+s[b:]\n if name=='ipv4_prefix.c':\n  a=s.index('    /* pattern restrictions */'); b=s.index('    /* get the mask',a); s=s[:a]+s[b:]\n if name in ['ipv4_prefix.c','ipv6_prefix.c']:\n  limit='32' if name=='ipv4_prefix.c' else '128'\n  old=\"    /* it passed the pattern validation */\\n    pref_str = ly_strnchr(value, '/', value_len);\\n    ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix);\"\n  new=f'''    /* Parse and check the prefix before using it to mask the address. */\n    pref_str = ly_strnchr(value, '/', value_len);\n    if (!pref_str || (pref_str + 1 == value + value_len) ||\n            ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix) || (*prefix > {limit})) {{\n        return ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, \"Invalid IPv{4 if limit=='32' else 6} prefix \\\"%.*s\\\".\", (int)value_len, value);\n    }}'''\n  # escape quotes for C\n  new=new.replace('prefix \"%.*s\".', 'prefix \\\\\"%.*s\\\\\".') if False else new.replace('prefix \"%.*s\".', 'prefix \\\\\"%.*s\\\\\".')\n  # python double escaping produces one backslash per quote\n  assert old in s; s=s.replace(old,new)\n p.write_text(s)\nPY\ncmake --build build -j4 > /tmp/libyang-build.log 2>&1; tail -100 /tmp/libyang-build.log",
  "timeout": 120000
}
Turn 8evr/openai/gpt-6.1-terra@medium28,013 in · 95 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
[  1%] Built target fuzz_regression_test
Consolidate compiler generated dependencies of target yangobj
[  2%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/binary.c.o
[  2%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/union.c.o
[  3%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/decimal64.c.o
[  4%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/string.c.o
/testbed/src/plugins_types/decimal64.c:173:1: warning: ‘static’ is not at beginning of declaration [-Wold-style-declaration]
  173 | static LY_ERR
      | ^~~~~~
/testbed/src/plugins_types/decimal64.c:173:1: error: duplicate ‘static’
/testbed/src/plugins_types/decimal64.c:174:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘lyplg_type_validate_decimal64’
  174 | lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/testbed/src/plugins_types/decimal64.c:274:28: warning: initialization of ‘LY_ERR (*)(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, const struct lysc_ext_instance *, struct lyd_value *, struct ly_err_item **)’ from incompatible pointer type ‘LY_ERR (*)(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, struct lyd_value *, struct ly_err_item **)’ [-Wincompatible-pointer-types]
  274 |         .plugin.validate = lyplg_type_validate_decimal64,
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/testbed/src/plugins_types/decimal64.c:274:28: note: (near initialization for ‘plugins_decimal64[0].plugin.validate’)
/testbed/src/plugins_types/decimal64.c:37:15: warning: ‘lyplg_type_validate_decimal64’ used but never defined
   37 | static LY_ERR lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gmake[2]: *** [CMakeFiles/yangobj.dir/build.make:832: CMakeFiles/yangobj.dir/src/plugins_types/decimal64.c.o] Error 1
gmake[2]: *** Waiting for unfinished jobs....
/testbed/src/plugins_types/string.c: In function ‘lyplg_type_store_string’:
/testbed/src/plugins_types/string.c:69:27: warning: unused variable ‘type_str’ [-Wunused-variable]
   69 |     struct lysc_type_str *type_str = (struct lysc_type_str *)type;
      |                           ^~~~~~~~
/testbed/src/plugins_types/string.c: In function ‘lyplg_type_validate_string’:
/testbed/src/plugins_types/string.c:145:48: warning: passing argument 1 of ‘lyplg_type_validate_patterns’ from incompatible pointer type [-Wincompatible-pointer-types]
  145 |     ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
      |                                        ~~~~~~~~^~~~~~~~~~
      |                                                |
      |                                                struct lysc_pattern **
In file included from /testbed/src/plugins_types/string.c:16:
/testbed/build/libyang/plugins_types.h:851:75: note: expected ‘const struct ly_ctx *’ but argument is of type ‘struct lysc_pattern **’
  851 | LIBYANG_API_DECL LY_ERR lyplg_type_validate_patterns(const struct ly_ctx *ctx, struct lysc_pattern **patterns,
      |                                                      ~~~~~~~~~~~~~~~~~~~~~^~~
/testbed/src/plugins_types/string.c:145:60: warning: passing argument 2 of ‘lyplg_type_validate_patterns’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  145 |     ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
      |                                                            ^~~~~
In file included from /testbed/src/plugins_types/string.c:16:
/testbed/build/libyang/plugins_types.h:851:102: note: expected ‘struct lysc_pattern **’ but argument is of type ‘const void *’
  851 | LIBYANG_API_DECL LY_ERR lyplg_type_validate_patterns(const struct ly_ctx *ctx, struct lysc_pattern **patterns,
      |                                                                                ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/testbed/src/plugins_types/string.c:145:67: warning: passing argument 3 of ‘lyplg_type_validate_patterns’ makes pointer from integer without a cast [-Wint-conversion]
  145 |     ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
      |                                                                   ^~~~~~~~~
      |                                                                   |
      |                                                                   size_t {aka long unsigned int}
In file included from /testbed/src/plugins_types/string.c:16:
/testbed/build/libyang/plugins_types.h:852:21: note: expected ‘const char *’ but argument is of type ‘size_t’ {aka ‘long unsigned int’}
  852 |         const char *str, uint32_t str_len, struct ly_err_item **err);
      |         ~~~~~~~~~~~~^~~
/testbed/src/plugins_types/string.c:145:78: warning: passing argument 4 of ‘lyplg_type_validate_patterns’ makes integer from pointer without a cast [-Wint-conversion]
  145 |     ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
      |                                                                              ^~~
      |                                                                              |
      |                                                                              struct ly_err_item **
In file included from /testbed/src/plugins_types/string.c:16:
/testbed/build/libyang/plugins_types.h:852:35: note: expected ‘uint32_t’ {aka ‘unsigned int’} but argument is of type ‘struct ly_err_item **’
  852 |         const char *str, uint32_t str_len, struct ly_err_item **err);
      |                          ~~~~~~~~~^~~~~~~
/testbed/src/plugins_types/string.c:145:11: error: too few arguments to function ‘lyplg_type_validate_patterns’
  145 |     ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /testbed/src/plugins_types/string.c:16:
/testbed/build/libyang/plugins_types.h:851:25: note: declared here
  851 | LIBYANG_API_DECL LY_ERR lyplg_type_validate_patterns(const struct ly_ctx *ctx, struct lysc_pattern **patterns,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/testbed/src/plugins_types/string.c: At top level:
/testbed/src/plugins_types/string.c:167:28: warning: initialization of ‘LY_ERR (*)(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, const struct lysc_ext_instance *, struct lyd_value *, struct ly_err_item **)’ from incompatible pointer type ‘LY_ERR (*)(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, struct lyd_value *, struct ly_err_item **)’ [-Wincompatible-pointer-types]
  167 |         .plugin.validate = lyplg_type_validate_string,
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~
/testbed/src/plugins_types/string.c:167:28: note: (near initialization for ‘plugins_string[0].plugin.validate’)
gmake[2]: *** [CMakeFiles/yangobj.dir/build.make:958: CMakeFiles/yangobj.dir/src/plugins_types/string.c.o] Error 1
/testbed/src/plugins_types/binary.c:354:1: warning: ‘static’ is not at beginning of declaration [-Wold-style-declaration]
  354 | static LY_ERR
      | ^~~~~~
/testbed/src/plugins_types/binary.c:354:1: error: duplicate ‘static’
/testbed/src/plugins_types/binary.c:355:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘lyplg_type_validate_binary’
  355 | lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
/testbed/src/plugins_types/binary.c:514:28: warning: initialization of ‘LY_ERR (*)(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, const struct lysc_ext_instance *, struct lyd_value *, struct ly_err_item **)’ from incompatible pointer type ‘LY_ERR (*)(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, struct lyd_value *, struct ly_err_item **)’ [-Wincompatible-pointer-types]
  514 |         .plugin.validate = lyplg_type_validate_binary,
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~
/testbed/src/plugins_types/binary.c:514:28: note: (near initialization for ‘plugins_binary[0].plugin.validate’)
/testbed/src/plugins_types/binary.c:48:15: warning: ‘lyplg_type_validate_binary’ used but never defined
   48 | static LY_ERR lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~
gmake[2]: *** [CMakeFiles/yangobj.dir/build.make:790: CMakeFiles/yangobj.dir/src/plugins_types/binary.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:396: CMakeFiles/yangobj.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
bash: line 1: python3: command not found
</output>

Model

THOUGHT: The edit script did not run because Python is unavailable, so no source changes were made. I’ll use the installed scripting tools instead.

▸bash{
{
  "command": "cd /testbed && command -v perl; command -v python; command -v ruby; git status --short | head"
}
Turn 9evr/openai/gpt-6.1-terra@medium28,129 in · 1,126 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
/usr/bin/perl
?? build/
</output>

Model

THOUGHT: Perl is available. I’ll apply the same edits using targeted substitutions, then inspect the compiler’s feedback.

▸bash{
{
  "command": "cd /testbed && perl -0777 -i -pe 's/const struct lyd_node \\*UNUSED\\(tree\\), struct lyd_value \\*storage, struct ly_err_item \\*\\*err\\)/const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext),\\n        struct lyd_value *storage, struct ly_err_item **err)/g; s/const struct lyd_node \\*tree, struct lyd_value \\*storage, struct ly_err_item \\*\\*err\\);/const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,\\n        struct lyd_value *storage, struct ly_err_item **err);/g; s/(lyplg_type_validate_(?:decimal64|int|uint|binary|string)\\(ctx, type, NULL, NULL), storage, err\\)/$1, NULL, storage, err)/g; s/static LY_ERR\\n(?=\\/\\*\\*\\n \\* \\@brief Implementation of ::lyplg_type_validate_clb)//g' src/plugins_types/{decimal64,integer,binary,string}.c\nperl -0777 -i -pe 's/    struct lysc_type_str \\*type_str = \\(struct lysc_type_str \\*\\)type;\\n(?=    uint32_t value_size;)//; s/lyplg_type_validate_patterns\\(type_str->patterns/lyplg_type_validate_patterns(ctx, type_str->patterns/' src/plugins_types/string.c\nperl -0777 -i -pe 's/    \\/\\* length restriction of the string \\*\\/\\n.*?    \\/\\* pattern restrictions \\*\\/\\n.*?    LY_CHECK_GOTO\\(ret, cleanup\\);\\n\\n//s' src/plugins_types/{hex_string,ipv4_address_no_zone,xpath1.0}.c\nperl -0777 -i -pe 's/    \\/\\* length restriction, there can be only ASCII chars \\*\\/\\n.*?(?=    \\/\\* convert to UNIX time)//s' src/plugins_types/date_and_time.c\nperl -0777 -i -pe 's/    \\/\\* pattern restrictions \\*\\/\\n.*?(?=    \\/\\* get the mask)//s' src/plugins_types/ipv4_prefix.c\nperl -0777 -i -pe 's/    struct lysc_type_str \\*type_(?:str|dat) = \\(struct lysc_type_str \\*\\)type;\\n//' src/plugins_types/{date_and_time,ipv4_address_no_zone,ipv4_prefix,ipv6_address_no_zone,ipv6_prefix,xpath1.0}.c\nperl -0777 -i -pe 's@    /\\* it passed the pattern validation \\*/\\n    pref_str = ly_strnchr\\(value, '\\''/'\\'', value_len\\);\\n    ly_strntou8\\(pref_str \\+ 1, value_len - \\(pref_str \\+ 1 - value\\), prefix\\);@    /* Parse and check the prefix before masking the address. */\\n    pref_str = ly_strnchr(value, '\\''/'\\'', value_len);\\n    if (!pref_str || (pref_str + 1 == value + value_len) ||\\n            ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix) || (*prefix > 32)) {\\n        return ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, \"Invalid IPv4 prefix \\\\\"%.*s\\\\\".\", (int)value_len, value);\\n    }@' src/plugins_types/ipv4_prefix.c\nperl -0777 -i -pe 's@    /\\* it passed the pattern validation \\*/\\n    pref_str = ly_strnchr\\(value, '\\''/'\\'', value_len\\);\\n    ly_strntou8\\(pref_str \\+ 1, value_len - \\(pref_str \\+ 1 - value\\), prefix\\);@    /* Parse and check the prefix before masking the address. */\\n    pref_str = ly_strnchr(value, '\\''/'\\'', value_len);\\n    if (!pref_str || (pref_str + 1 == value + value_len) ||\\n            ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix) || (*prefix > 128)) {\\n        return ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, \"Invalid IPv6 prefix \\\\\"%.*s\\\\\".\", (int)value_len, value);\\n    }@' src/plugins_types/ipv6_prefix.c\ncmake --build build -j4 > /tmp/libyang-build.log 2>&1; tail -80 /tmp/libyang-build.log",
  "timeout": 120000
}
Turn 10evr/openai/gpt-6.1-terra@medium30,857 in · 185 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
[ 75%] Linking C executable ../utest_lyb
[ 75%] Linking C executable ../utest_validation
[ 75%] Built target utest_printer_json
[ 75%] Building C object tests/utests/CMakeFiles/utest_merge.dir/data/test_merge.c.o
[ 75%] Built target utest_parser_json
[ 76%] Linking C executable ../utest_merge
[ 76%] Building C object tests/utests/CMakeFiles/utest_diff.dir/data/test_diff.c.o
[ 76%] Built target utest_lyb
[ 76%] Building C object tests/utests/CMakeFiles/utest_metadata.dir/extensions/test_metadata.c.o
[ 77%] Linking C executable ../utest_metadata
[ 77%] Linking C executable ../utest_diff
[ 77%] Built target utest_validation
[ 77%] Building C object tests/utests/CMakeFiles/utest_nacm.dir/extensions/test_nacm.c.o
[ 78%] Linking C executable ../utest_nacm
[ 78%] Built target utest_merge
[ 79%] Building C object tests/utests/CMakeFiles/utest_yangdata.dir/extensions/test_yangdata.c.o
[ 79%] Built target utest_metadata
[ 79%] Built target utest_diff
[ 79%] Building C object tests/utests/CMakeFiles/utest_schema_mount.dir/extensions/test_schema_mount.c.o
[ 79%] Building C object tests/utests/CMakeFiles/utest_structure.dir/extensions/test_structure.c.o
[ 79%] Linking C executable ../utest_yangdata
[ 79%] Linking C executable ../utest_structure
[ 80%] Linking C executable ../utest_schema_mount
[ 80%] Built target utest_nacm
[ 80%] Building C object tests/style/CMakeFiles/cpp_compat.dir/cpp_compat.c.o
[ 80%] Built target utest_yangdata
[ 81%] Building C object tests/fuzz/CMakeFiles/regress_fuzz_lys_parse_mem.dir/lys_parse_mem.c.o
[ 81%] Linking C executable ../../cpp_compat
[ 81%] Built target utest_structure
[ 81%] Building C object tests/fuzz/CMakeFiles/regress_fuzz_lys_parse_mem.dir/main.c.o
[ 81%] Built target utest_schema_mount
[ 81%] Building C object tests/fuzz/CMakeFiles/regress_fuzz_lyd_parse_mem_xml.dir/lyd_parse_mem_xml.c.o
[ 81%] Building C object tests/fuzz/CMakeFiles/regress_fuzz_lyd_parse_mem_json.dir/lyd_parse_mem_json.c.o
[ 82%] Linking C executable lys_parse_mem/regress_fuzz_lys_parse_mem
[ 83%] Building C object tests/fuzz/CMakeFiles/regress_fuzz_lyd_parse_mem_xml.dir/main.c.o
[ 83%] Built target regress_fuzz_lys_parse_mem
[ 84%] Building C object tests/fuzz/CMakeFiles/regress_fuzz_lyd_parse_mem_json.dir/main.c.o
[ 84%] Linking C executable lyd_parse_mem_xml/regress_fuzz_lyd_parse_mem_xml
[ 85%] Building C object tests/perf/CMakeFiles/ly_perf.dir/perf.c.o
[ 85%] Linking C executable lyd_parse_mem_json/regress_fuzz_lyd_parse_mem_json
[ 85%] Built target regress_fuzz_lyd_parse_mem_xml
[ 85%] Built target regress_fuzz_lyd_parse_mem_json
[ 86%] Building C object tools/lint/CMakeFiles/yanglint.dir/main_ni.c.o
[ 87%] Building C object tools/re/CMakeFiles/yangre.dir/main.c.o
[ 87%] Linking C executable ../ly_perf
[ 87%] Built target cpp_compat
[ 87%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd.c.o
[ 88%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_add.c.o
[ 88%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_clear.c.o
[ 88%] Building C object tools/re/CMakeFiles/yangre.dir/__/__/compat/compat.c.o
[ 89%] Linking C executable ../../yangre
[ 90%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_data.c.o
[ 90%] Building C object tests/plugins/CMakeFiles/plugin_invalid.dir/invalid.c.o
[ 90%] Built target yangre
[ 91%] Linking C shared module plugin_invalid.so
[ 91%] Building C object tests/plugins/CMakeFiles/plugin_simple.dir/simple.c.o
[ 91%] Built target ly_perf
[ 91%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_list.c.o
[ 91%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_feature.c.o
[ 91%] Built target plugin_invalid
[ 92%] Linking C shared module plugin_simple.so
[ 93%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_load.c.o
[ 93%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_print.c.o
[ 93%] Built target plugin_simple
[ 94%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_searchpath.c.o
[ 94%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_extdata.c.o
[ 95%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_help.c.o
[ 95%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_verb.c.o
[ 95%] Building C object tools/lint/CMakeFiles/yanglint.dir/cmd_debug.c.o
[ 96%] Building C object tools/lint/CMakeFiles/yanglint.dir/yl_opt.c.o
[ 96%] Building C object tools/lint/CMakeFiles/yanglint.dir/yl_schema_features.c.o
[ 97%] Building C object tools/lint/CMakeFiles/yanglint.dir/common.c.o
[ 97%] Building C object tools/lint/CMakeFiles/yanglint.dir/main.c.o
[ 97%] Building C object tools/lint/CMakeFiles/yanglint.dir/completion.c.o
[ 98%] Building C object tools/lint/CMakeFiles/yanglint.dir/configuration.c.o
[ 98%] Building C object tools/lint/CMakeFiles/yanglint.dir/linenoise/linenoise.c.o
[ 99%] Building C object tools/lint/CMakeFiles/yanglint.dir/linenoise/utf8.c.o
[ 99%] Building C object tools/lint/CMakeFiles/yanglint.dir/__/__/compat/compat.c.o
[100%] Linking C executable ../../yanglint
[100%] Built target yanglint
</output>

Model

THOUGHT: The project now builds successfully. I’ll review the patch and run the existing test suite to identify regressions, especially around built-in restrictions and date parsing.

▸bash{
{
  "command": "cd /testbed && git diff --stat && git diff && grep -n 'warning:' /tmp/libyang-build.log | head -40",
  "max_output_chars": 35000
}
▸bash{
{
  "command": "cd /testbed/build && ctest --output-on-failure -j4 > /tmp/libyang-ctest.log 2>&1; tail -100 /tmp/libyang-ctest.log",
  "timeout": 120000
}
Turn 11evr/openai/gpt-6.1-terra@medium35,374 in · 266 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<warning>
The output of your last command was too long.
Please try a different command that produces less output.
If you're looking at a file you can try use head, tail or sed to view a smaller number of lines selectively.
If you're using grep or find and it produced too much output, you can use a more selective search pattern.
If you really need to see something from the full command's output, you can redirect output to a file and then search in that file.
</warning><output_head>
 src/plugins_types/binary.c               |  9 +++++----
 src/plugins_types/date_and_time.c        | 11 -----------
 src/plugins_types/decimal64.c            |  9 +++++----
 src/plugins_types/hex_string.c           | 11 -----------
 src/plugins_types/integer.c              | 16 ++++++++++------
 src/plugins_types/ipv4_address_no_zone.c | 12 ------------
 src/plugins_types/ipv4_prefix.c          | 16 +++++-----------
 src/plugins_types/ipv6_address_no_zone.c |  1 -
 src/plugins_types/ipv6_prefix.c          |  8 +++++---
 src/plugins_types/string.c               | 11 ++++++-----
 src/plugins_types/xpath1.0.c             | 12 ------------
 11 files changed, 36 insertions(+), 80 deletions(-)
diff --git a/src/plugins_types/binary.c b/src/plugins_types/binary.c
index 1eb3b6872..3a09a7e41 100644
--- a/src/plugins_types/binary.c
+++ b/src/plugins_types/binary.c
@@ -46,7 +46,8 @@ static const char b64_etable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst
 
 static void lyplg_type_free_binary(const struct ly_ctx *ctx, struct lyd_value *value);
 static LY_ERR lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type,
-        const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err);
+        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,
+        struct lyd_value *storage, struct ly_err_item **err);
 
 /**
  * @brief Encode binary value into a base64 string value.
@@ -332,7 +333,7 @@ lyplg_type_store_binary(const struct ly_ctx *ctx, const struct lysc_type *type,
 
     if (!(options & LYPLG_TYPE_STORE_ONLY)) {
         /* validate value */
-        ret = lyplg_type_validate_binary(ctx, type, NULL, NULL, storage, err);
+        ret = lyplg_type_validate_binary(ctx, type, NULL, NULL, NULL, storage, err);
         LY_CHECK_GOTO(ret, cleanup);
     }
 
@@ -347,13 +348,13 @@ cleanup:
     return ret;
 }
 
-static LY_ERR
 /**
  * @brief Implementation of ::lyplg_type_validate_clb for the binary type.
  */
 static LY_ERR
 lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
-        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
+        const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext),
+        struct lyd_value *storage, struct ly_err_item **err)
 {
     struct lysc_type_bin *type_bin = (struct lysc_type_bin *)type;
     struct lyd_value_binary *val;
diff --git a/src/plugins_types/date_and_time.c b/src/plugins_types/date_and_time.c
index 4acb63e78..8a09c0550 100644
--- a/src/plugins_types/date_and_time.c
+++ b/src/plugins_types/date_and_time.c
@@ -53,7 +53,6 @@ lyplg_type_store_date_and_time(const struct ly_ctx *ctx, const struct lysc_type
         struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
 {
     LY_ERR ret = LY_SUCCESS;
-    struct lysc_type_str *type_dat = (struct lysc_type_str *)type;
     struct lyd_value_date_and_time *val;
     uint32_t i, value_size;
     char c;
@@ -108,16 +107,6 @@ lyplg_type_store_date_and_time(const struct ly_ctx *ctx, const struct lysc_type
     ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
     LY_CHECK_GOTO(ret, cleanup);
 
-    /* length restriction, there can be only ASCII chars */
-    if (type_dat->length) {
-        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_dat->length, value_len, value, value_len, err);
-        LY_CHECK_GOTO(ret, cleanup);
-    }
-
-    /* date-and-time pattern */
-    ret = lyplg_type_validate_patterns(type_dat->patterns, value, value_len, err);
-    LY_CHECK_GOTO(ret, cleanup);
-
     /* convert to UNIX time and fractions of second */
     ret = ly_time_str2time(value, &val->time, &val->fractions_s);
     if (ret) {
diff --git a/src/plugins_types/decimal64.c b/src/plugins_types/decimal64.c
index fe77f2278..f25d9cb44 100644
--- a/src/plugins_types/decimal64.c
+++ b/src/plugins_types/decimal64.c
@@ -34,7 +34,8 @@
  * | 64        | yes | `int64_t *` | little-endian value represented without floating point |
  */
 
-static LY_ERR lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err);
+static LY_ERR lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext),
+        struct lyd_value *storage, struct ly_err_item **err);
 
 /**
  * @brief Convert decimal64 number to canonical string.
@@ -151,7 +152,7 @@ lyplg_type_store_decimal64(const struct ly_ctx *ctx, const struct lysc_type *typ
 
     if (!(options & LYPLG_TYPE_STORE_ONLY)) {
         /* validate value */
-   
</output_head>
<elided_chars>
9506 characters elided
</elided_chars>
<output_tail>
lue_len - (pref_str + 1 - value), prefix);
+    if (!pref_str || (pref_str + 1 == value + value_len) ||
+            ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix) || (*prefix > 128)) {
+        return ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid IPv6 prefix \"%.*s\".", (int)value_len, value);
+    }
 
     /* get just the network prefix */
     mask_str = strndup(value, pref_str - value);
@@ -130,7 +133,6 @@ lyplg_type_store_ipv6_prefix(const struct ly_ctx *ctx, const struct lysc_type *t
         struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
 {
     LY_ERR ret = LY_SUCCESS;
-    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
     struct lyd_value_ipv6_prefix *val;
     uint32_t value_size;
 
diff --git a/src/plugins_types/string.c b/src/plugins_types/string.c
index 90c64b98b..979dcc920 100644
--- a/src/plugins_types/string.c
+++ b/src/plugins_types/string.c
@@ -34,7 +34,8 @@
  * | variable, full bytes | yes | `char *` | string itself |
  */
 
-static LY_ERR lyplg_type_validate_string(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err);
+static LY_ERR lyplg_type_validate_string(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext),
+        struct lyd_value *storage, struct ly_err_item **err);
 
 /**
  * @brief Check string value for invalid characters.
@@ -66,7 +67,6 @@ lyplg_type_store_string(const struct ly_ctx *ctx, const struct lysc_type *type,
         struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
 {
     LY_ERR ret = LY_SUCCESS;
-    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
     uint32_t value_size;
 
     /* init storage */
@@ -102,7 +102,7 @@ lyplg_type_store_string(const struct ly_ctx *ctx, const struct lysc_type *type,
 
     if (!(options & LYPLG_TYPE_STORE_ONLY)) {
         /* validate value */
-        ret = lyplg_type_validate_string(ctx, type, NULL, NULL, storage, err);
+        ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err);
         LY_CHECK_GOTO(ret, cleanup);
     }
 
@@ -122,7 +122,8 @@ cleanup:
  */
 static LY_ERR
 lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
-        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
+        const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext),
+        struct lyd_value *storage, struct ly_err_item **err)
 {
     LY_ERR ret;
     struct lysc_type_str *type_str = (struct lysc_type_str *)type;
@@ -142,7 +143,7 @@ lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *typ
     }
 
     /* pattern restrictions */
-    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
+    ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_len, err);
     LY_CHECK_RET(ret);
 
     return LY_SUCCESS;
diff --git a/src/plugins_types/xpath1.0.c b/src/plugins_types/xpath1.0.c
index 5544148cc..a78eef1a1 100644
--- a/src/plugins_types/xpath1.0.c
+++ b/src/plugins_types/xpath1.0.c
@@ -250,7 +250,6 @@ lyplg_type_store_xpath10(const struct ly_ctx *ctx, const struct lysc_type *type,
 {
     LY_ERR ret = LY_SUCCESS;
     uint32_t value_size;
-    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
     struct lyd_value_xpath10 *val;
     char *canon;
 
@@ -269,17 +268,6 @@ lyplg_type_store_xpath10(const struct ly_ctx *ctx, const struct lysc_type *type,
     ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
     LY_CHECK_GOTO(ret, cleanup);
 
-    /* length restriction of the string */
-    if (type_str->length) {
-        /* value_len is in bytes, but we need number of characters here */
-        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
-        LY_CHECK_GOTO(ret, cleanup);
-    }
-
-    /* pattern restrictions */
-    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
-    LY_CHECK_GOTO(ret, cleanup);
-
     /* parse */
     ret = lyxp_expr_parse(ctx, value_size ? value : "", value_size, 1, &val->exp);
     LY_CHECK_GOTO(ret, cleanup);
8:/testbed/src/plugins_types/integer.c:56:27: warning: unused variable ‘type_num’ [-Wunused-variable]
12:/testbed/src/plugins_types/integer.c:363:27: warning: unused variable ‘type_num’ [-Wunused-variable]
20:/testbed/src/plugins_types/ipv4_address.c:129:27: warning: unused variable ‘type_str’ [-Wunused-variable]
24:/testbed/src/plugins_types/ipv6_address.c:130:27: warning: unused variable ‘type_str’ [-Wunused-variable]

</output_tail>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
27/60 Test #27: utest_set .........................   Passed    0.02 sec
      Start 31: utest_plugins
28/60 Test #28: utest_hash_table ..................   Passed    0.02 sec
      Start 32: utest_xml
29/60 Test #31: utest_plugins .....................   Passed    0.01 sec
      Start 33: utest_json
30/60 Test #29: utest_inout .......................   Passed    0.02 sec
      Start 34: utest_xpath
31/60 Test #32: utest_xml .........................   Passed    0.02 sec
      Start 35: utest_yanglib
32/60 Test #35: utest_yanglib .....................   Passed    0.01 sec
      Start 36: utest_schema
33/60 Test #33: utest_json ........................   Passed    0.01 sec
      Start 37: utest_yang
34/60 Test #30: utest_context .....................   Passed    0.06 sec
      Start 38: utest_yin
35/60 Test #34: utest_xpath .......................   Passed    0.05 sec
      Start 39: utest_tree_schema_compile
36/60 Test #37: utest_yang ........................   Passed    0.05 sec
      Start 40: utest_printer_tree
37/60 Test #36: utest_schema ......................   Passed    0.06 sec
      Start 41: utest_tree_data
38/60 Test #41: utest_tree_data ...................   Passed    0.04 sec
      Start 42: utest_tree_data_sorted
39/60 Test #39: utest_tree_schema_compile .........   Passed    0.09 sec
      Start 43: utest_new
40/60 Test #43: utest_new .........................   Passed    0.01 sec
      Start 44: utest_parser_xml
41/60 Test #38: utest_yin .........................   Passed    0.11 sec
      Start 45: utest_printer_xml
42/60 Test #45: utest_printer_xml .................   Passed    0.01 sec
      Start 46: utest_printer_json
43/60 Test #40: utest_printer_tree ................   Passed    0.11 sec
      Start 47: utest_parser_json
44/60 Test #46: utest_printer_json ................   Passed    0.01 sec
      Start 48: utest_lyb
45/60 Test #42: utest_tree_data_sorted ............   Passed    0.08 sec
      Start 49: utest_validation
46/60 Test #44: utest_parser_xml ..................   Passed    0.05 sec
      Start 50: utest_merge
47/60 Test #47: utest_parser_json .................   Passed    0.04 sec
      Start 51: utest_diff
48/60 Test #48: utest_lyb .........................   Passed    0.04 sec
      Start 52: utest_metadata
49/60 Test #52: utest_metadata ....................   Passed    0.01 sec
      Start 53: utest_nacm
50/60 Test #50: utest_merge .......................   Passed    0.03 sec
      Start 54: utest_yangdata
51/60 Test #49: utest_validation ..................   Passed    0.05 sec
      Start 55: utest_schema_mount
52/60 Test #53: utest_nacm ........................   Passed    0.01 sec
      Start 56: utest_structure
53/60 Test #54: utest_yangdata ....................   Passed    0.01 sec
      Start 57: headers
54/60 Test #56: utest_structure ...................   Passed    0.01 sec
      Start 58: regress_fuzz_lys_parse_mem
55/60 Test #51: utest_diff ........................   Passed    0.05 sec
      Start 59: regress_fuzz_lyd_parse_mem_xml
56/60 Test #59: regress_fuzz_lyd_parse_mem_xml ....   Passed    0.07 sec
      Start 60: regress_fuzz_lyd_parse_mem_json
57/60 Test #55: utest_schema_mount ................***Failed    0.11 sec
[==========] Running 10 test(s).
[ RUN      ] test_schema
[       OK ] test_schema
[ RUN      ] test_parse_invalid
[       OK ] test_parse_invalid
[ RUN      ] test_parse_inline
[       OK ] test_parse_inline
[ RUN      ] test_parse_shared
[       OK ] test_parse_shared
[ RUN      ] test_parse_shared_parent_ref
[       OK ] test_parse_shared_parent_ref
[ RUN      ] test_dup_shared
[       OK ] test_dup_shared
[ RUN      ] test_parse_config
[       OK ] test_parse_config
[ RUN      ] test_new
[       OK ] test_new
[ RUN      ] test_lys_getnext
[       OK ] test_lys_getnext
[ RUN      ] test_xpath
Could not run test: "Ext plugin "ly2 schema mount": Must condition "/m:root/l1 = 'valid'" not satisfied." != "Ext plugin "ly2 schema mount v1": Must condition "/m:root/l1 = 'valid'" not satisfied."
[   LINE   ] --- /testbed/tests/utests/extensions/test_schema_mount.c:1862: error: Failure!ly_err_last(current_utest_context->ctx)
[   LINE   ] --- /testbed/tests/utests/utests.h:1351: error: Failure!Test teardown failed
[  ERROR   ] test_xpath
[==========] 10 test(s) run.
[  PASSED  ] 9 test(s).

58/60 Test #60: regress_fuzz_lyd_parse_mem_json ...   Passed    0.10 sec
59/60 Test #58: regress_fuzz_lys_parse_mem ........   Passed    0.29 sec
60/60 Test #57: headers ...........................   Passed    0.40 sec

97% tests passed, 2 tests failed out of 60

Total Test time (real) =   0.78 sec

The following tests FAILED:
	 13 - utest_yang_types (Failed)
	 55 - utest_schema_mount (Failed)
Errors while running CTest
</output>

Model

THOUGHT: Most tests pass; schema-mount’s existing test expects the obsolete versioned name, while its actual output already matches the requested name. I’ll inspect the other failure and verify the malformed date error directly.

▸bash{
{
  "command": "sed -n '/utest_yang_types.*Failed/,/Start 14/p' /tmp/libyang-ctest.log | head -180; cd /testbed && git diff --check && git diff -- src/plugins_types/integer.c"
}
▸bash{
{
  "command": "cd /testbed && ls build/yanglint modules | head; grep -n '2005-05-31T23:15:15\\|date-and-time' tests/utests/types/test_yang_types.c | head -35; grep -R -n 'lyplg_type_store_hex_string\\|LY_TYPE_STRING.*plugin' src | head -60; grep -n 'ly_time_str2time\\|strndup\\|value_size' src/plugins_types/date_and_time.c | head -30"
}
Turn 12evr/openai/gpt-6.1-terra@medium39,215 in · 256 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
13/60 Test #13: utest_yang_types ..................***Failed    0.02 sec
[==========] Running 5 test(s).
[ RUN      ] test_data_xml
ERROR: LY_EVALID != 0x3; MSG: Missing date-and-time fractions after '.'.
Could not run test: [   LINE   ] --- /testbed/tests/utests/types/yang_types.c:114: error: Failure!ly_err_last(current_utest_context->ctx)
[   LINE   ] --- /testbed/tests/utests/types/../utests.h:1351: error: Failure!Test teardown failed
[  ERROR   ] test_data_xml
[ RUN      ] test_print
[       OK ] test_print
[ RUN      ] test_duplicate
[       OK ] test_duplicate
[ RUN      ] test_lyb
[       OK ] test_lyb
[ RUN      ] test_sort
[       OK ] test_sort
[==========] 5 test(s) run.
[  PASSED  ] 4 test(s).

      Start 17: utest_union
14/60 Test #16: utest_instanceid_keys .............   Passed    0.01 sec
      Start 18: utest_boolean
15/60 Test #14: utest_enumeration .................   Passed    0.02 sec
      Start 19: utest_decimal64
16/60 Test #15: utest_instanceid ..................   Passed    0.01 sec
      Start 20: utest_empty
17/60 Test #18: utest_boolean .....................   Passed    0.01 sec
      Start 21: utest_identityref
18/60 Test #17: utest_union .......................   Passed    0.02 sec
      Start 22: utest_leafref
19/60 Test #19: utest_decimal64 ...................   Passed    0.01 sec
      Start 23: utest_range
20/60 Test #20: utest_empty .......................   Passed    0.01 sec
      Start 24: utest_pattern
21/60 Test #21: utest_identityref .................   Passed    0.01 sec
      Start 25: utest_list
22/60 Test #22: utest_leafref .....................   Passed    0.02 sec
      Start 26: utest_common
23/60 Test #23: utest_range .......................   Passed    0.02 sec
      Start 27: utest_set
24/60 Test #24: utest_pattern .....................   Passed    0.02 sec
      Start 28: utest_hash_table
25/60 Test #25: utest_list ........................   Passed    0.02 sec
      Start 29: utest_inout
26/60 Test #26: utest_common ......................   Passed    0.02 sec
      Start 30: utest_context
27/60 Test #27: utest_set .........................   Passed    0.02 sec
      Start 31: utest_plugins
28/60 Test #28: utest_hash_table ..................   Passed    0.02 sec
      Start 32: utest_xml
29/60 Test #31: utest_plugins .....................   Passed    0.01 sec
      Start 33: utest_json
30/60 Test #29: utest_inout .......................   Passed    0.02 sec
      Start 34: utest_xpath
31/60 Test #32: utest_xml .........................   Passed    0.02 sec
      Start 35: utest_yanglib
32/60 Test #35: utest_yanglib .....................   Passed    0.01 sec
      Start 36: utest_schema
33/60 Test #33: utest_json ........................   Passed    0.01 sec
      Start 37: utest_yang
34/60 Test #30: utest_context .....................   Passed    0.06 sec
      Start 38: utest_yin
35/60 Test #34: utest_xpath .......................   Passed    0.05 sec
      Start 39: utest_tree_schema_compile
36/60 Test #37: utest_yang ........................   Passed    0.05 sec
      Start 40: utest_printer_tree
37/60 Test #36: utest_schema ......................   Passed    0.06 sec
      Start 41: utest_tree_data
38/60 Test #41: utest_tree_data ...................   Passed    0.04 sec
      Start 42: utest_tree_data_sorted
39/60 Test #39: utest_tree_schema_compile .........   Passed    0.09 sec
      Start 43: utest_new
40/60 Test #43: utest_new .........................   Passed    0.01 sec
      Start 44: utest_parser_xml
41/60 Test #38: utest_yin .........................   Passed    0.11 sec
      Start 45: utest_printer_xml
42/60 Test #45: utest_printer_xml .................   Passed    0.01 sec
      Start 46: utest_printer_json
43/60 Test #40: utest_printer_tree ................   Passed    0.11 sec
      Start 47: utest_parser_json
44/60 Test #46: utest_printer_json ................   Passed    0.01 sec
      Start 48: utest_lyb
45/60 Test #42: utest_tree_data_sorted ............   Passed    0.08 sec
      Start 49: utest_validation
46/60 Test #44: utest_parser_xml ..................   Passed    0.05 sec
      Start 50: utest_merge
47/60 Test #47: utest_parser_json .................   Passed    0.04 sec
      Start 51: utest_diff
48/60 Test #48: utest_lyb .........................   Passed    0.04 sec
      Start 52: utest_metadata
49/60 Test #52: utest_metadata ....................   Passed    0.01 sec
      Start 53: utest_nacm
50/60 Test #50: utest_merge .......................   Passed    0.03 sec
      Start 54: utest_yangdata
51/60 Test #49: utest_validation ..................   Passed    0.05 sec
      Start 55: utest_schema_mount
52/60 Test #53: utest_nacm ........................   Passed    0.01 sec
      Start 56: utest_structure
53/60 Test #54: utest_yangdata ....................   Passed    0.01 sec
      Start 57: headers
54/60 Test #56: utest_structure ...................   Passed    0.01 sec
      Start 58: regress_fuzz_lys_parse_mem
55/60 Test #51: utest_diff ........................   Passed    0.05 sec
      Start 59: regress_fuzz_lyd_parse_mem_xml
56/60 Test #59: regress_fuzz_lyd_parse_mem_xml ....   Passed    0.07 sec
      Start 60: regress_fuzz_lyd_parse_mem_json
57/60 Test #55: utest_schema_mount ................***Failed    0.11 sec
[==========] Running 10 test(s).
[ RUN      ] test_schema
[       OK ] test_schema
[ RUN      ] test_parse_invalid
[       OK ] test_parse_invalid
[ RUN      ] test_parse_inline
[       OK ] test_parse_inline
[ RUN      ] test_parse_shared
[       OK ] test_parse_shared
[ RUN      ] test_parse_shared_parent_ref
[       OK ] test_parse_shared_parent_ref
[ RUN      ] test_dup_shared
[       OK ] test_dup_shared
[ RUN      ] test_parse_config
[       OK ] test_parse_config
[ RUN      ] test_new
[       OK ] test_new
[ RUN      ] test_lys_getnext
[       OK ] test_lys_getnext
[ RUN      ] test_xpath
Could not run test: "Ext plugin "ly2 schema mount": Must condition "/m:root/l1 = 'valid'" not satisfied." != "Ext plugin "ly2 schema mount v1": Must condition "/m:root/l1 = 'valid'" not satisfied."
[   LINE   ] --- /testbed/tests/utests/extensions/test_schema_mount.c:1862: error: Failure!ly_err_last(current_utest_context->ctx)
[   LINE   ] --- /testbed/tests/utests/utests.h:1351: error: Failure!Test teardown failed
[  ERROR   ] test_xpath
[==========] 10 test(s) run.
[  PASSED  ] 9 test(s).

58/60 Test #60: regress_fuzz_lyd_parse_mem_json ...   Passed    0.10 sec
59/60 Test #58: regress_fuzz_lys_parse_mem ........   Passed    0.29 sec
60/60 Test #57: headers ...........................   Passed    0.40 sec

97% tests passed, 2 tests failed out of 60

Total Test time (real) =   0.78 sec

The following tests FAILED:
	 13 - utest_yang_types (Failed)
	 55 - utest_schema_mount (Failed)
Errors while running CTest
diff --git a/src/plugins_types/integer.c b/src/plugins_types/integer.c
index 91afa85e4..abf6d390a 100644
--- a/src/plugins_types/integer.c
+++ b/src/plugins_types/integer.c
@@ -40,9 +40,11 @@
  */
 
 static LY_ERR lyplg_type_validate_int(const struct ly_ctx *ctx, const struct lysc_type *type,
-        const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err);
+        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,
+        struct lyd_value *storage, struct ly_err_item **err);
 static LY_ERR lyplg_type_validate_uint(const struct ly_ctx *ctx, const struct lysc_type *type,
-        const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err);
+        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,
+        struct lyd_value *storage, struct ly_err_item **err);
 
 static LY_ERR
 lyplg_type_store_int(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits,
@@ -155,7 +157,7 @@ lyplg_type_store_int(const struct ly_ctx *ctx, const struct lysc_type *type, con
 
     if (!(options & LYPLG_TYPE_STORE_ONLY)) {
         /* validate value */
-        ret = lyplg_type_validate_int(ctx, type, NULL, NULL, storage, err);
+        ret = lyplg_type_validate_int(ctx, type, NULL, NULL, NULL, storage, err);
         LY_CHECK_GOTO(ret, cleanup);
     }
 
@@ -175,7 +177,8 @@ cleanup:
  */
 static LY_ERR
 lyplg_type_validate_int(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
-        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
+        const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext),
+        struct lyd_value *storage, struct ly_err_item **err)
 {
     LY_ERR ret;
     struct lysc_type_num *type_num = (struct lysc_type_num *)type;
@@ -441,7 +444,7 @@ lyplg_type_store_uint(const struct ly_ctx *ctx, const struct lysc_type *type, co
 
     if (!(options & LYPLG_TYPE_STORE_ONLY)) {
         /* validate value */
-        ret = lyplg_type_validate_uint(ctx, type, NULL, NULL, storage, err);
+        ret = lyplg_type_validate_uint(ctx, type, NULL, NULL, NULL, storage, err);
         LY_CHECK_GOTO(ret, cleanup);
     }
 
@@ -461,7 +464,8 @@ cleanup:
  */
 static LY_ERR
 lyplg_type_validate_uint(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
-        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
+        const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext),
+        struct lyd_value *storage, struct ly_err_item **err)
 {
     LY_ERR ret;
     struct lysc_type_num *type_num = (struct lysc_type_num *)type;
</output>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
build/yanglint

modules:
default@2025-06-18.h
default@2025-06-18.yang
ietf-datastores@2018-02-14.h
ietf-datastores@2018-02-14.yang
ietf-inet-types@2013-07-15.h
ietf-inet-types@2013-07-15.yang
ietf-yang-library@2019-01-04.h
src/plugins_types/hex_string.c:41:lyplg_type_store_hex_string(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits,
src/plugins_types/hex_string.c:129:        .plugin.store = lyplg_type_store_hex_string,
src/plugins_types/hex_string.c:144:        .plugin.store = lyplg_type_store_hex_string,
src/plugins_types/hex_string.c:159:        .plugin.store = lyplg_type_store_hex_string,
src/plugins_types/hex_string.c:174:        .plugin.store = lyplg_type_store_hex_string,
50:lyplg_type_store_date_and_time(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits,
57:    uint32_t i, value_size;
68:        if (value_size_bits < 64) {
70:                    " b (expected at least 64 b).", value_size_bits);
73:        value_size = LYPLG_BITS2BYTES(value_size_bits);
74:        for (i = 9; i < value_size; ++i) {
87:        if (value_size > 9) {
88:            val->fractions_s = strndup(((char *)value) + 9, value_size - 9);
93:        if (value_size > 8) {
102:    ret = lyplg_type_check_value_size("date-and-time", format, value_size_bits, LYPLG_LYB_SIZE_VARIABLE_BYTES, 0,
103:            &value_size, err);
107:    ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
111:    ret = ly_time_str2time(value, &val->time, &val->fractions_s);
117:    if (!strncmp(((char *)value + value_size) - 6, "-00:00", 6)) {
129:            ret = lydict_insert(ctx, value, value_size, &storage->_canonical);
260:        void *UNUSED(prefix_data), ly_bool *dynamic, uint32_t *value_size_bits)
274:            if (value_size_bits) {
275:                *value_size_bits = 64 + 8 + (val->fractions_s ? strlen(val->fractions_s) * 8 : 0);
284:            if (value_size_bits) {
285:                *value_size_bits = 64;
321:    if (value_size_bits) {
322:        *value_size_bits = strlen(value->_canonical) * 8;
grep: tests/utests/types/test_yang_types.c: No such file or directory
</output>

Model

THOUGHT: Both test failures reflect outdated expectations for the exact behaviors requested in the PR. I’ll verify the error code and path with a small external reproduction, and tidy the callback declarations and existing unused numeric locals.

▸bash{
{
  "command": "cd /testbed && sed -n '75,125p' tests/utests/types/yang_types.c; sed -n '45,65p;355,370p' src/plugins_types/integer.c; grep -n 'lyd_parse_data_mem\\|ly_err_last\\|lys_parse_mem' src/{parser_data.h,parser_schema.h,log.h} | head -30; ls build | grep '\\.so' | head; grep -n 'typedef enum.*LY_ERR\\|LY_EINVAL' src/log.h | head"
}
Turn 13evr/openai/gpt-6.1-terra@medium40,956 in · 929 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
        lyd_free_all(tree_1); \
        lyd_free_all(tree_2); \
    }

static void
test_data_xml(void **state)
{
    const char *schema;

    /* xml test */
    schema = MODULE_CREATE_YANG("a",
            "leaf l {type yang:date-and-time;}"
            "leaf l21 {type yang:hex-string;}"
            "leaf l22 {type yang:uuid;}"
            "leaf l3 {type yang:xpath1.0;}");
    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
    schema = MODULE_CREATE_YANG("b",
            "");
    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);

    /* date-and-time */
    TEST_SUCCESS_XML("a", "l", "2005-05-25T23:15:15.88888Z", STRING, "2005-05-25T21:15:15.88888-02:00");
    TEST_SUCCESS_XML("a", "l", "2005-05-31T23:15:15-08:59", STRING, "2005-06-01T06:14:15-02:00");
    TEST_SUCCESS_XML("a", "l", "2005-05-31T23:15:15-23:00", STRING, "2005-06-01T20:15:15-02:00");

    /* test 1 second before epoch (mktime returns -1, but it is a correct value), with and without DST */
    TEST_SUCCESS_XML("a", "l", "1970-01-01T00:59:59-02:00", STRING, "1970-01-01T00:59:59-02:00");
    TEST_SUCCESS_XML("a", "l", "1969-12-31T23:59:59-02:00", STRING, "1969-12-31T23:59:59-02:00");

    /* canonize */
    TEST_SUCCESS_XML("a", "l", "2005-02-29T23:15:15-02:00", STRING, "2005-03-01T23:15:15-02:00");

    /* fractional hours */
    TEST_SUCCESS_XML("a", "l", "2005-05-25T23:15:15.88888+04:30", STRING, "2005-05-25T16:45:15.88888-02:00");

    /* unknown timezone -- timezone conversion MUST NOT happen */
    TEST_SUCCESS_XML("a", "l", "2017-02-01T00:00:00-00:00", STRING, "2017-02-01T00:00:00-00:00");
    TEST_SUCCESS_XML("a", "l", "2021-02-29T00:00:00-00:00", STRING, "2021-03-01T00:00:00-00:00");

    TEST_ERROR_XML("a", "l", "2005-05-31T23:15:15.-08:00", LY_EVALID);
    CHECK_LOG_CTX("Unsatisfied pattern - \"2005-05-31T23:15:15.-08:00\" does not conform to "
            "\"\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[\\+\\-]\\d{2}:\\d{2})\".",
            "/a:l", 1);

    TEST_ERROR_XML("a", "l", "2023-16-15T20:13:01+01:00", LY_EINVAL);
    CHECK_LOG_CTX("Invalid date-and-time month \"15\".", "/a:l", 1);

    TEST_ERROR_XML("a", "l", "2023-10-15T20:13:01+95:00", LY_EINVAL);
    CHECK_LOG_CTX("Invalid date-and-time timezone hour \"95\".", "/a:l", 1);

    /* hex-string */
static LY_ERR lyplg_type_validate_uint(const struct ly_ctx *ctx, const struct lysc_type *type,
        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,
        struct lyd_value *storage, struct ly_err_item **err);

static LY_ERR
lyplg_type_store_int(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits,
        uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints,
        const struct lysc_node *UNUSED(ctx_node), const struct lysc_ext_instance *UNUSED(top_ext),
        struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    struct lysc_type_num *type_num = (struct lysc_type_num *)type;
    uint32_t value_size;
    int64_t num = 0;
    int base = 1;
    char *canon = NULL;

    /* init storage */
    memset(storage, 0, sizeof *storage);
    storage->realtype = type;


static LY_ERR
lyplg_type_store_uint(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits,
        uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints,
        const struct lysc_node *UNUSED(ctx_node), const struct lysc_ext_instance *UNUSED(top_ext),
        struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    struct lysc_type_num *type_num = (struct lysc_type_num *)type;
    uint32_t value_size;
    uint64_t num = 0;
    int base = 0;
    char *canon;

    /* init storage */
    memset(storage, 0, sizeof *storage);
src/parser_data.h:75: * - ::lyd_parse_data_mem()
src/parser_data.h:264:LIBYANG_API_DECL LY_ERR lyd_parse_data_mem(const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, uint32_t parse_options,
src/parser_schema.h:74: * - ::lys_parse_mem()
src/parser_schema.h:122:LIBYANG_API_DECL LY_ERR lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format, struct lys_module **module);
src/log.h:217: * accessed using ::ly_err_last() or ::ly_err_first() functions. The ::ly_err_clean() is used to remove error records from the
src/log.h:335:LIBYANG_API_DECL const struct ly_err_item *ly_err_last(const struct ly_ctx *ctx);
libyang.so
libyang.so.3
libyang.so.3.9.13
241:    LY_EINVAL,      /**< Invalid value */
</output>

Model

THOUGHT: The date test explicitly expects the old pattern error, confirming the failure is intentional. I’ll clean up the touched declarations and use a standalone API check for the new error code, message, and node path.

▸bash{
{
  "command": "cd /testbed && perl -0777 -i -pe 's/static LY_ERR lyplg_type_validate_decimal64\\(const struct ly_ctx \\*UNUSED\\(ctx\\), const struct lysc_type \\*type, const struct lyd_node \\*UNUSED\\(ctx_node\\), const struct lyd_node \\*UNUSED\\(tree\\), const struct lysc_ext_instance \\*UNUSED\\(top_ext\\),/static LY_ERR lyplg_type_validate_decimal64(const struct ly_ctx *ctx, const struct lysc_type *type,\\n        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,/' src/plugins_types/decimal64.c\nperl -0777 -i -pe 's/static LY_ERR lyplg_type_validate_string\\(const struct ly_ctx \\*UNUSED\\(ctx\\), const struct lysc_type \\*type, const struct lyd_node \\*UNUSED\\(ctx_node\\), const struct lyd_node \\*UNUSED\\(tree\\), const struct lysc_ext_instance \\*UNUSED\\(top_ext\\),/static LY_ERR lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type,\\n        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,/' src/plugins_types/string.c\nperl -0777 -i -pe 's/    struct lysc_type_num \\*type_num = \\(struct lysc_type_num \\*\\)type;\\n(?=    uint32_t value_size;)//g' src/plugins_types/integer.c\ncat >/tmp/libyang-pr-check.c <<'EOF'\n#include <stdio.h>\n#include <string.h>\n#include <libyang/libyang.h>\nint main(void) {\n    struct ly_ctx *ctx = NULL;\n    struct lys_module *mod = NULL;\n    struct lyd_node *tree = NULL;\n    const struct ly_err_item *e;\n    LY_ERR rc;\n    const char *schema = \"module a {yang-version 1.1; namespace 'urn:a'; prefix a; import ietf-yang-types { prefix yang; } leaf l {type yang:date-and-time;} }\";\n    ly_log_options(LY_LOSTORE);\n    if (ly_ctx_new(NULL, 0, &ctx) || lys_parse_mem(ctx, schema, LYS_IN_YANG, &mod)) return 1;\n    rc = lyd_parse_data_mem(ctx, \"<l xmlns='urn:a'>2005-05-31T23:15:15.-08:00</l>\", LYD_XML, LYD_PARSE_STRICT, 0, &tree);\n    e = ly_err_last(ctx);\n    printf(\"rc=%d expected=%d message=%s path=%s\\n\", rc, LY_EINVAL, e ? e->msg : \"(null)\", e && e->data_path ? e->data_path : \"(null)\");\n    if (rc != LY_EINVAL || !e || strcmp(e->msg, \"Missing date-and-time fractions after '.'.\") || !e->data_path || strcmp(e->data_path, \"/a:l\")) return 2;\n    lyd_free_all(tree); ly_ctx_destroy(ctx); return 0;\n}\nEOF\ncmake --build build -j4 >/tmp/libyang-build2.log 2>&1 && cc -Ibuild /tmp/libyang-pr-check.c -Lbuild -Wl,-rpath,/testbed/build -lyang -o /tmp/libyang-pr-check && /tmp/libyang-pr-check; git diff --check",
  "timeout": 120000
}
Turn 14evr/openai/gpt-6.1-terra@medium41,870 in · 287 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
rc=3 expected=3 message=Missing date-and-time fractions after '.'. path=(null)
</output>

Model

THOUGHT: The API reproduction confirms the correct error code and message, but the final error item has no data path. I’ll inspect how parser errors attach paths so the requested node path is verified correctly.

▸bash{
{
  "command": "cd /testbed && sed -n '250,290p' src/log.h; grep -n -A35 '#define CHECK_LOG_CTX' tests/utests/utests.h; grep -n -A15 '#define TEST_ERROR_XML' tests/utests/types/yang_types.c tests/utests/utests.h; grep -R -n 'ly_err_new(err, ret, 0, NULL, NULL, \"%s\", ly_last_logmsg' src"
}
▸bash{
{
  "command": "cd /testbed && grep -R -n 'ly_err_print\\|ly_err_item.*path\\|err->data_path\\|err->schema_path' src/parser* src/tree_data* src/plugins_types.c | head -100; git diff --stat && cat /tmp/libyang-build2.log | grep warning | head"
}
Turn 15evr/openai/gpt-6.1-terra@medium44,115 in · 307 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
                         According to the specific use case, the caller should react appropriately. */
    LY_ENOT,        /**< Negative result */
    LY_EOTHER,      /**< Unknown error */

    LY_EPLUGIN = 128/**< Error reported by a plugin - the highest bit in the first byte is set.
                         This value is used ORed with one of the other LY_ERR value and can be simply masked. */
} LY_ERR;

/**
 * @ingroup log
 * @typedef LY_VECODE
 * @brief libyang's codes of validation error. Whenever ly_errno is set to LY_EVALID, the ly_vecode is also set
 * to the appropriate LY_VECODE value.
 */
typedef enum {
    LYVE_SUCCESS = 0,  /**< no error */
    LYVE_SYNTAX,       /**< generic syntax error */
    LYVE_SYNTAX_YANG,  /**< YANG-related syntax error */
    LYVE_SYNTAX_YIN,   /**< YIN-related syntax error */
    LYVE_REFERENCE,    /**< invalid referencing or using an item */
    LYVE_XPATH,        /**< invalid XPath expression */
    LYVE_SEMANTICS,    /**< generic semantic error */
    LYVE_SYNTAX_XML,   /**< XML-related syntax error */
    LYVE_SYNTAX_JSON,  /**< JSON-related syntax error */
    LYVE_DATA,         /**< YANG data does not reflect some of the module restrictions */

    LYVE_OTHER         /**< Unknown error */
} LY_VECODE;

/**
 * @brief Libyang full error structure.
 */
struct ly_err_item {
    LY_LOG_LEVEL level;         /**< error (message) log level */
    LY_ERR err;                 /**< error code number */
    LY_VECODE vecode;           /**< validation error code, if any */
    char *msg;                  /**< error message */
    char *data_path;            /**< error data path related to the error, if any */
    char *schema_path;          /**< error schema path related to the error, if any */
    uint64_t line;              /**< input line the error occured on, if available */
    char *apptag;               /**< error-app-tag, if any */
1241:#define CHECK_LOG_CTX(MSG, PATH, LINE) \
1242-    { \
1243-        struct ly_err_item *_e = (struct ly_err_item *)ly_err_last(_UC->ctx); \
1244-        if (!MSG) { \
1245-            assert_null(_e); \
1246-        } else { \
1247-            assert_non_null(_e); \
1248-            CHECK_STRING(_e->msg, MSG); \
1249-            if (_e->data_path) { \
1250-                CHECK_STRING(_e->data_path, PATH); \
1251-            } else { \
1252-                CHECK_STRING(_e->schema_path, PATH); \
1253-            } \
1254-            assert_int_equal(_e->line, LINE); \
1255-        } \
1256-        ly_err_clean(_UC->ctx, _e); \
1257-    }
1258-
1259-/**
1260- * @brief Check expected error in libyang context including error-app-tag.
1261- *
1262- * @param[in] MSG Expected error message.
1263- * @param[in] PATH Expected error data/schema path.
1264- * @param[in] LINE Expected error line.
1265- * @param[in] APPTAG Expected error-app-tag.
1266- */
1267:#define CHECK_LOG_CTX_APPTAG(MSG, PATH, LINE, APPTAG) \
1268-    { \
1269-        struct ly_err_item *_e = (struct ly_err_item *)ly_err_last(_UC->ctx); \
1270-        if (!MSG) { \
1271-            assert_null(_e); \
1272-        } else { \
1273-            assert_non_null(_e); \
1274-            CHECK_STRING(_e->msg, MSG); \
1275-            if (_e->data_path) { \
1276-                CHECK_STRING(_e->data_path, PATH); \
1277-            } else { \
1278-                CHECK_STRING(_e->schema_path, PATH); \
1279-            } \
1280-            assert_int_equal(_e->line, LINE); \
1281-            CHECK_STRING(_e->apptag, APPTAG); \
1282-        } \
1283-        ly_err_clean(_UC->ctx, _e); \
1284-    }
1285-
1286-/**
1287- * @brief Clear all errors stored in the libyang context.
1288- */
1289-#define UTEST_LOG_CTX_CLEAN \
1290-    ly_err_clean(_UC->ctx, NULL)
1291-
1292-#ifdef _UTEST_MAIN_
1293-/*
1294- * Functions inlined into each C source file including this header with _UTEST_MAIN_ defined
1295- */
1296-
1297-/**
1298- * @brief Global variable holding the tests context to simplify access to it.
1299- */
1300-struct utest_context *current_utest_context;
1301-
1302-/**
tests/utests/types/yang_types.c:55:#define TEST_ERROR_XML(MOD_NAME, NODE_NAME, DATA, RET) \
tests/utests/types/yang_types.c-56-    {\
tests/utests/types/yang_types.c-57-        struct lyd_node *tree; \
tests/utests/types/yang_types.c-58-        const char *data = "<" NODE_NAME " xmlns=\"urn:tests:" MOD_NAME "\">" DATA "</" NODE_NAME ">"; \
tests/utests/types/yang_types.c-59-        CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, RET, tree); \
tests/utests/types/yang_types.c-60-        assert_null(tree); \
tests/utests/types/yang_types.c-61-    }
tests/utests/types/yang_types.c-62-
tests/utests/types/yang_types.c-63-#define TEST_SUCCESS_LYB(MOD_NAME, NODE_NAME, DATA) \
tests/utests/types/yang_types.c-64-    { \
tests/utests/types/yang_types.c-65-        struct lyd_node *tree_1; \
tests/utests/types/yang_types.c-66-        struct lyd_node *tree_2; \
tests/utests/types/yang_types.c-67-        char *xml_out, *data; \
tests/utests/types/yang_types.c-68-        data = "<" NODE_NAME " xmlns=\"urn:tests:" MOD_NAME "\">" DATA "</" NODE_NAME ">"; \
tests/utests/types/yang_types.c-69-        CHECK_PARSE_LYD_PARAM(data, LYD_XML, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, LY_SUCCESS, tree_1); \
tests/utests/types/yang_types.c-70-        assert_int_equal(lyd_print_mem(&xml_out, tree_1, LYD_LYB, LYD_PRINT_WITHSIBLINGS), 0); \
src/plugins_types/date_and_time.c:113:        ret = ly_err_new(err, ret, 0, NULL, NULL, "%s", ly_last_logmsg());
</output>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
src/parser_common.c:122:        ly_err_print(ctx, err);
src/tree_data_common.c:489:ly_err_print_build_path(const struct ly_ctx *ctx, const struct lyd_node *node, const struct lysc_node *scnode,
src/tree_data_common.c:493:        ly_err_print(ctx, eitem);
src/tree_data_common.c:549:            ly_err_print_build_path(ctx, NULL, ctx_node, err);
src/tree_data_common.c:574:            ly_err_print_build_path(ctx, ctx_node, NULL, err);
src/tree_data_common.c:611:            ly_err_print_build_path(ctx, NULL, node, err);
src/tree_data_common.c:669:            ly_err_print_build_path(ctx, ctx_node, schema, err);
src/tree_data_common.c:1888:        ly_err_print(ctx, err);
src/plugins_types.c:959:            ly_err_print(node->module->ctx, err);
 src/plugins_types/binary.c               |  9 +++++----
 src/plugins_types/date_and_time.c        | 11 -----------
 src/plugins_types/decimal64.c            | 10 ++++++----
 src/plugins_types/hex_string.c           | 11 -----------
 src/plugins_types/integer.c              | 18 ++++++++++--------
 src/plugins_types/ipv4_address_no_zone.c | 12 ------------
 src/plugins_types/ipv4_prefix.c          | 16 +++++-----------
 src/plugins_types/ipv6_address_no_zone.c |  1 -
 src/plugins_types/ipv6_prefix.c          |  8 +++++---
 src/plugins_types/string.c               | 12 +++++++-----
 src/plugins_types/xpath1.0.c             | 12 ------------
 11 files changed, 38 insertions(+), 82 deletions(-)
</output>

Model

THOUGHT: Parser errors may report the node as a schema path rather than a data path, as the existing test helper confirms. I’ll update the external check to accept either representation and rerun it.

▸bash{
{
  "command": "sed -i 's/e \\&\\& e->data_path ? e->data_path : \"(null)\"/e \\&\\& e->data_path ? e->data_path : (e \\&\\& e->schema_path ? e->schema_path : \"(null)\")/; s/!e->data_path || strcmp(e->data_path, \"\\/a:l\")/!(e->data_path || e->schema_path) || strcmp(e->data_path ? e->data_path : e->schema_path, \"\\/a:l\")/' /tmp/libyang-pr-check.c\ncd /testbed && cc -Ibuild /tmp/libyang-pr-check.c -Lbuild -Wl,-rpath,/testbed/build -lyang -o /tmp/libyang-pr-check && /tmp/libyang-pr-check && git diff --check && grep -n 'warning:' /tmp/libyang-build2.log | head",
  "timeout": 120000
}
Turn 16evr/openai/gpt-6.1-terra@medium44,427 in · 359 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
rc=3 expected=3 message=Missing date-and-time fractions after '.'. path=/a:l
</output>

Model

THOUGHT: The requested date behavior now reproduces with the correct code, message, and node path. I’ll inspect the framework’s handling of derived-type restrictions before deciding whether the remaining functional hex-string checks can safely be removed.

▸bash{
{
  "command": "cd /testbed && grep -R -n -- '->validate(' src | head -100; grep -R -n -- 'plugin->validate\\|plugin.validate\\|realtype->plugin' src/tree_data* src/validation.c src/plugins_types/union.c | head -120; sed -n '500,690p' src/tree_data_common.c; sed -n '125,165p' tests/utests/types/yang_types.c",
  "max_output_chars": 16000
}
▸bash{
{
  "command": "cd /testbed && sed -n '40,115p' src/plugins_types/hex_string.c; grep -R -n 'LYPLG_TYPE_STORE_ONLY' src | head -80; sed -n '1685,1760p' src/tree_data_common.c"
}
Turn 17evr/openai/gpt-6.1-terra@medium49,454 in · 403 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<warning>
The output of your last command was too long.
Please try a different command that produces less output.
If you're looking at a file you can try use head, tail or sed to view a smaller number of lines selectively.
If you're using grep or find and it produced too much output, you can use a more selective search pattern.
If you really need to see something from the full command's output, you can redirect output to a file and then search in that file.
</warning><output_head>
src/plugins_types/union.c:295:        rc = type_plg->validate(ctx, type, ctx_node, tree, top_ext, &subvalue->value, err);
src/tree_data_common.c:571:    ret = type_plg->validate(ctx, type, ctx_node, tree, top_ext, val, &err);
src/tree_data_common.c:663:        rc = type_plg->validate(ctx, type, ctx_node, ctx_node, top_ext, &val, &err);
src/validation.c:463:            r = LYSC_GET_EXT_PLG(ext_v->ext->def->plugin_ref)->validate(ext_v->ext, ext_v->sibling, *tree,
src/tree_data.c:1875:    return LYSC_GET_TYPE_PLG(meta1->value.realtype->plugin_ref)->compare(ctx, &meta1->value, &meta2->value);
src/tree_data.c:2251:            rc = LYSC_GET_TYPE_PLG(orig->value.realtype->plugin_ref)->duplicate(trg_ctx, &orig->value, &term->value);
src/tree_data.c:2554:        ret = LYSC_GET_TYPE_PLG(meta->value.realtype->plugin_ref)->duplicate(parent_ctx, &meta->value, &mt->value);
src/tree_data_common.c:686:            lydict_dup(ctx, LYSC_GET_TYPE_PLG(val.realtype->plugin_ref)->print(ctx, &val,
src/tree_data_common.c:1000:           (const char *)LYSC_GET_TYPE_PLG(value->realtype->plugin_ref)->print(ctx, value, LY_VALUE_CANON, NULL, NULL, NULL);
src/tree_data_free.c:68:        LYSC_GET_TYPE_PLG(meta->value.realtype->plugin_ref)->free(meta->annotation->module->ctx, &meta->value);
src/tree_data_hash.c:59:                hash_key = LYSC_GET_TYPE_PLG(key->value.realtype->plugin_ref)->print(NULL, &key->value,
src/tree_data_hash.c:71:        hash_key = LYSC_GET_TYPE_PLG(llist->value.realtype->plugin_ref)->print(NULL, &llist->value,
src/tree_data_new.c:1222:    realtype_plg = LYSC_GET_TYPE_PLG(term->value.realtype->plugin_ref);
src/tree_data_sorted.c:199:    return LYSC_GET_TYPE_PLG(val1->realtype->plugin_ref)->sort(ctx, val1, val2);
src/plugins_types/union.c:252:            value = LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref)->print(ctx, &subvalue->value,
src/plugins_types/union.c:540:    subvalue_type_plg = LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref);
src/plugins_types/union.c:572:    LYSC_GET_TYPE_PLG(orig.realtype->plugin_ref)->free(ctx, &orig);
src/plugins_types/union.c:582:    return LYSC_GET_TYPE_PLG(val1->subvalue->value.realtype->plugin_ref)->compare(ctx,
src/plugins_types/union.c:594:        return LYSC_GET_TYPE_PLG(val1->subvalue->value.realtype->plugin_ref)->sort(ctx,
src/plugins_types/union.c:649:    LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref)->free(ctx, &subvalue->value);
src/plugins_types/union.c:655:    pval = (void *)LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref)->print(NULL, &subvalue->value, LY_VALUE_LYB,
src/plugins_types/union.c:702:    ret = (void *)LYSC_GET_TYPE_PLG(subvalue->value.realtype->plugin_ref)->print(ctx, &subvalue->value,
src/plugins_types/union.c:729:    ret = LYSC_GET_TYPE_PLG(orig_val->value.realtype->plugin_ref)->duplicate(ctx, &orig_val->value, &dup_val->value);
src/plugins_types/union.c:765:            LYSC_GET_TYPE_PLG(val->value.realtype->plugin_ref)->free(ctx, &val->value);
src/plugins_types/union.c:790:        .plugin.validate = lyplg_type_validate_union,
        ly_vlog(ctx, eitem->apptag, eitem->err == LY_EVALID ? eitem->vecode : LYVE_DATA, "%s", eitem->msg);
        if (node) {
            LOG_LOCBACK(0, 1);
        } else if (scnode) {
            LOG_LOCBACK(1, 0);
        }
    }
}

LY_ERR
lyd_value_store(const struct ly_ctx *ctx, struct lyd_value *val, const struct lysc_type *type, const void *value,
        uint32_t value_size_bits, ly_bool is_utf8, ly_bool store_only, ly_bool *dynamic, LY_VALUE_FORMAT format,
        void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node, const struct lysc_ext_instance *top_ext,
        ly_bool *incomplete)
{
    LY_ERR r;
    struct ly_err_item *err = NULL;
    uint32_t options = 0;

    if (!value) {
        value = "";
        value_size_bits = 0;
    }
    if (incomplete) {
        *incomplete = 0;
    }

    if (dynamic && *dynamic) {
        options |= LYPLG_TYPE_STORE_DYNAMIC;
    }
    if (is_utf8) {
        options |= LYPLG_TYPE_STORE_IS_UTF8;
    }
    if (store_only) {
        options |= LYPLG_TYPE_STORE_ONLY;
    }

    r = LYSC_GET_TYPE_PLG(type->plugin_ref)->store(ctx, type, value, value_size_bits, options, format, prefix_data,
            hints, ctx_node, top_ext, val, NULL, &err);
    if (dynamic) {
        *dynamic = 0;
    }

    if (r == LY_EINCOMPLETE) {
        if (incomplete) {
            *incomplete = 1;
        }
    } else if (r) {
        if (err) {
            ly_err_print_build_path(ctx, NULL, ctx_node, err);
            ly_err_free(err);
        } else {
            LOGVAL(ctx, LYVE_OTHER, "Storing value failed.");
        }
        return r;
    }

    return LY_SUCCESS;
}

LY_ERR
lyd_value_validate_incomplete(const struct ly_ctx *ctx, const struct lysc_type *type, struct lyd_value *val,
        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext)
{
    LY_ERR ret;
    struct ly_err_item *err = NULL;
    struct ly
</output_head>
<elided_chars>
1202 characters elided
</elided_chars>
<output_tail>
>module->ctx, type, value,
            value_size_bits, 0, format, prefix_data, hints, node, top_ext, &storage, NULL, &err);
    if (rc == LY_EINCOMPLETE) {
        /* actually success */
        rc = LY_SUCCESS;
    } else if (rc && err) {
        if (ctx) {
            /* log only in case the ctx was provided as input parameter */
            ly_err_print_build_path(ctx, NULL, node, err);
        }
        ly_err_free(err);
    }

    if (!rc) {
        LYSC_GET_TYPE_PLG(type->plugin_ref)->free(ctx ? ctx : node->module->ctx, &storage);
    }
    return rc;
}

LIBYANG_API_DEF LY_ERR
lyd_value_validate(const struct ly_ctx *ctx, const struct lysc_node *schema, const char *value, uint32_t value_len,
        const struct lyd_node *ctx_node, const struct lysc_type **realtype, const char **canonical)
{
    LY_CHECK_ARG_RET(ctx, schema, !value_len || value, LY_EINVAL);

    return lyd_value_validate2(ctx, schema, value, value_len, LY_VALUE_JSON, NULL, ctx_node, NULL, realtype, canonical);
}

LY_ERR
lyd_value_validate2(const struct ly_ctx *ctx, const struct lysc_node *schema, const char *value, size_t value_len,
        LY_VALUE_FORMAT format, void *prefix_data, const struct lyd_node *ctx_node,
        const struct lysc_ext_instance *top_ext, const struct lysc_type **realtype, const char **canonical)
{
    LY_ERR rc;
    struct ly_err_item *err = NULL;
    struct lysc_type *type;
    struct lyd_value val = {0};
    ly_bool stored = 0, log = 1;
    struct lyplg_type *type_plg;

    if (!ctx) {
        ctx = schema->module->ctx;
        log = 0;
    }
    if (!value_len) {
        value = "";
    }
    type = ((struct lysc_node_leaf *)schema)->type;

    type_plg = LYSC_GET_TYPE_PLG(type->plugin_ref);

    /* store */
    rc = type_plg->store(ctx, type, value, value_len * 8, 0, format, prefix_data, LYD_HINT_DATA, schema, top_ext, &val,
            NULL, &err);
    if (!rc || (rc == LY_EINCOMPLETE)) {
        stored = 1;
    }

    if (ctx_node && (rc == LY_EINCOMPLETE)) {
        /* resolve */
        rc = type_plg->validate(ctx, type, ctx_node, ctx_node, top_ext, &val, &err);
    }

    if (rc && (rc != LY_EINCOMPLETE) && err) {
        if (log) {
            /* log error */
            ly_err_print_build_path(ctx, ctx_node, schema, err);
        }
        ly_err_free(err);
    }

    if (!rc || (rc == LY_EINCOMPLETE)) {
        if (realtype) {
            /* return realtype */
            if (val.realtype->basetype == LY_TYPE_UNION) {
                *realtype = val.subvalue->value.realtype;
            } else {
                *realtype = val.realtype;
            }
        }

        if (canonical) {
            /* return canonical value */
            lydict_dup(ctx, LYSC_GET_TYPE_PLG(val.realtype->plugin_ref)->print(ctx, &val,
                    LY_VALUE_CANON, NULL, NULL, NULL), canonical);
        }
    }

    /* hex-string */
    TEST_SUCCESS_XML("a", "l21", "DB:BA:12:54:fa", STRING, "db:ba:12:54:fa");
    TEST_SUCCESS_XML("a", "l22", "f81D4fAE-7dec-11d0-A765-00a0c91E6BF6", STRING, "f81d4fae-7dec-11d0-a765-00a0c91e6bf6");

    /* xpath1.0 */
    TEST_SUCCESS_XML("a\" xmlns:aa=\"urn:tests:a", "l3", "/aa:l3[. = '4']", STRING, "/a:l3[.='4']");
    TEST_SUCCESS_XML("a\" xmlns:yl=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\" "
            "xmlns:ds=\"urn:ietf:params:xml:ns:yang:ietf-datastores", "l3",
            "/yl:yang-library/yl:datastore/yl:name = 'ds:running'", STRING,
            "/ietf-yang-library:yang-library/datastore/name='ietf-datastores:running'");
    TEST_SUCCESS_XML("a\" xmlns:a1=\"urn:tests:a\" xmlns:a2=\"urn:tests:a\" xmlns:bb=\"urn:tests:b", "l3",
            "/a1:node1/a2:node2[a1:node3/bb:node4]/bb:node5 | bb:node6 and (bb:node7)", STRING,
            "/a:node1/node2[node3/b:node4]/b:node5 | b:node6 and (b:node7)");
    TEST_SUCCESS_XML("a", "l3", "/l3[. = '4']", STRING, "/l3[.='4']");

    TEST_ERROR_XML("a", "l3", "/a:l3[. = '4']", LY_EVALID);
    CHECK_LOG_CTX("Failed to resolve prefix \"a\".", "/a:l3", 1);
    TEST_ERROR_XML("a\" xmlns:yl=\"urn:ietf:params:xml:ns:yang:ietf-yang-library", "l3",
            "/yl:yang-library/yl:datastore/yl::name", LY_EVALID);
    CHECK_LOG_CTX("Storing value failed.", "/a:l3", 1);
    CHECK_LOG_CTX("Invalid character 'y'[31] of expression '/yl:yang-library/yl:datastore/yl::name'.", "/a:l3", 1);
}

static void
test_print(void **state)
{
    const char *schema = MODULE_CREATE_YANG("a", "leaf l {type yang:xpath1.0;}");
    const char *data, *expected;
    struct lyd_node *tree;

    UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);

    /* XML data */
    data = "<l xmlns=\"urn:tests:a\" xmlns:aa=\"urn:tests:a\">/aa:l[. = '/aa:l']</l>";
    CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, tree);

    /* XML print */
    expected = "<l xmlns=\"urn:tests:a\" xmlns:pref=\"urn:tests:a\">/pref:l[.='/pref:l']</l>";
    CHECK_LYD_STRING_PARAM(tree, expected, LYD_XML, LYD_PRINT_SHRINK | LYD_PRINT_WITHSIBLINGS);

    /* JSON print */

</output_tail>
▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
LIBYANG_API_DEF LY_ERR
lyplg_type_store_hex_string(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits,
        uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints,
        const struct lysc_node *UNUSED(ctx_node), const struct lysc_ext_instance *UNUSED(top_ext),
        struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
    uint32_t value_size, i;

    /* init storage */
    memset(storage, 0, sizeof *storage);
    storage->realtype = type;

    /* check value length */
    ret = lyplg_type_check_value_size("hex-string", format, value_size_bits, LYPLG_LYB_SIZE_VARIABLE_BYTES, 0,
            &value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* check hints */
    ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* make a copy, it is needed for canonization */
    if ((format != LY_VALUE_CANON) && !(options & LYPLG_TYPE_STORE_DYNAMIC)) {
        value = strndup(value, value_size);
        LY_CHECK_ERR_GOTO(!value, ret = LY_EMEM, cleanup);
        options |= LYPLG_TYPE_STORE_DYNAMIC;
    }

    /* store canonical value */
    if (format != LY_VALUE_CANON) {
        /* make lowercase and store, the value must be dynamic */
        for (i = 0; i < value_size; ++i) {
            ((char *)value)[i] = tolower(((char *)value)[i]);
        }

        ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
        options &= ~LYPLG_TYPE_STORE_DYNAMIC;
        LY_CHECK_GOTO(ret, cleanup);

        /* value may have been freed */
        value = storage->_canonical;
    } else {
        /* store directly */
        ret = lydict_insert(ctx, value_size ? value : "", value_size, &storage->_canonical);
        LY_CHECK_GOTO(ret, cleanup);
    }

    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
        /* validate length restriction of the string */
        if (type_str->length) {
            /* value_size is in bytes, but we need number of characters here */
            ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_size), value,
                    value_size, err);
            LY_CHECK_GOTO(ret, cleanup);
        }

        /* validate pattern restrictions */
        ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

cleanup:
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        free((void *)value);
    }

    if (ret) {
        lyplg_type_free_simple(ctx, storage);
    }
    return ret;
}

/**
 * @brief Plugin information for string type implementation.
src/plugins_types/binary.c:334:    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
src/plugins_types/hex_string.c:89:    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
src/plugins_types/decimal64.c:154:    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
src/plugins_types/string.c:104:    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
src/plugins_types/integer.c:157:    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
src/plugins_types/integer.c:443:    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
src/plugins_types/union.c:240:                    LYPLG_TYPE_STORE_ONLY, subvalue->format, subvalue->prefix_data, subvalue->hints,
src/plugins_types/union.c:276:    if (options & LYPLG_TYPE_STORE_ONLY) {
src/plugins_types/union.c:277:        opts |= LYPLG_TYPE_STORE_ONLY;
src/plugins_types/union.c:491:        options &= ~LYPLG_TYPE_STORE_ONLY;
src/plugins_types.c:955:    r = type_plg->store(node->module->ctx, type, canon, strlen(canon) * 8, LYPLG_TYPE_STORE_ONLY, LY_VALUE_CANON,
src/plugins_types.h:511:#define LYPLG_TYPE_STORE_ONLY      0x08 /**< The value is stored only, type-specific validation is skipped (performed before) */
src/tree_data_common.c:534:        options |= LYPLG_TYPE_STORE_ONLY;
    if (tm.tm_min > 59) {
        LOGERR(NULL, LY_EINVAL, "Invalid date-and-time minutes \"%d\".", tm.tm_min);
        return LY_EINVAL;
    }
    if (tm.tm_sec > 60) {
        LOGERR(NULL, LY_EINVAL, "Invalid date-and-time seconds \"%d\".", tm.tm_sec);
        return LY_EINVAL;
    }

    t = timegm(&tm);
    i = 19;

    /* fractions of a second */
    if (value[i] == '.') {
        ++i;
        frac = &value[i];
        for (frac_len = 0; isdigit(frac[frac_len]); ++frac_len) {}
        if (!frac_len) {
            LOGERR(NULL, LY_EINVAL, "Missing date-and-time fractions after '.'.");
            return LY_EINVAL;
        }

        i += frac_len;
    } else {
        frac = NULL;
    }

    /* apply offset */
    if ((value[i] == 'Z') || (value[i] == 'z')) {
        /* zero shift */
        shift = 0;
    } else {
        value += i;
        shift = strtol(value, &ptr, 10);
        if ((shift > 23) || (shift < -23)) {
            LOGERR(NULL, LY_EINVAL, "Invalid date-and-time timezone hour \"%" PRIi64 "\".", shift);
            return LY_EINVAL;
        } else if (ptr[0] != ':') {
            LOGERR(NULL, LY_EINVAL, "Invalid date-and-time timezone hour \"%s\".", value);
            return LY_EINVAL;
        }
        shift = shift * 60 * 60; /* convert from hours to seconds */

        value = ptr + 1;
        shift_m = strtol(value, NULL, 10);
        if ((shift_m < 0) || (shift_m > 59)) {
            LOGERR(NULL, LY_EINVAL, "Invalid date-and-time timezone minutes \"%" PRIi64 "\".", shift_m);
            return LY_EINVAL;
        }
        shift_m *= 60; /* convert from minutes to seconds */

        /* correct sign */
        if (shift < 0) {
            shift_m *= -1;
        }

        /* connect hours and minutes of the shift */
        shift = shift + shift_m;
    }

    /* we have to shift to the opposite way to correct the time */
    t -= shift;

    *time = t;
    if (fractions_s) {
        if (frac) {
            *fractions_s = strndup(frac, frac_len);
            LY_CHECK_RET(!*fractions_s, LY_EMEM);
        } else {
            *fractions_s = NULL;
        }
    }
    return LY_SUCCESS;
}

LIBYANG_API_DEF LY_ERR
</output>

Model

THOUGHT: The framework invokes each plugin’s own callback, not a generic base-string callback. Removing hex-string’s remaining checks without replacing them would silently disable constraints. I’ll move those checks into a dedicated callback and call it after storage, preserving validation and STORE_ONLY behavior.

▸bash{
{
  "command": "cd /testbed && sed -n '115,230p' src/plugins_types/instanceid_keys.c; sed -n '225,310p' src/plugins_types/union.c; sed -n '480,535p' src/plugins_types/union.c; sed -n '125,170p' src/plugins_types/string.c; sed -n '130,160p' src/plugins_types/ipv6_prefix.c"
}
Turn 18evr/openai/gpt-6.1-terra@medium52,344 in · 288 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<warning>
The output of your last command was too long.
Please try a different command that produces less output.
If you're looking at a file you can try use head, tail or sed to view a smaller number of lines selectively.
If you're using grep or find and it produced too much output, you can use a more selective search pattern.
If you really need to see something from the full command's output, you can redirect output to a file and then search in that file.
</warning><output_head>
            /* token processed */
            ++cur_idx;
        }
    }

cleanup:
    if (local_mod) {
        mods->objs[0] = (void *)local_mod;
    }
    if (ret) {
        free(*str_value);
        *str_value = NULL;
    }
    return ret;
}

/**
 * @brief Implementation of ::lyplg_type_store_clb for the instance-identifier-keys yang type.
 */
static LY_ERR
lyplg_type_store_instanceid_keys(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits,
        uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *UNUSED(ctx_node),
        const struct lysc_ext_instance *UNUSED(top_ext), struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres),
        struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
    struct lyd_value_instance_identifier_keys *val;
    uint32_t value_size, *prev_lo, temp_lo = LY_LOSTORE;
    const struct ly_err_item *eitem;
    char *canon;

    /* init storage */
    memset(storage, 0, sizeof *storage);
    LYPLG_TYPE_VAL_INLINE_PREPARE(storage, val);
    LY_CHECK_ERR_GOTO(!val, ret = LY_EMEM, cleanup);
    storage->realtype = type;

    /* check value length */
    ret = lyplg_type_check_value_size("instance-identifier-keys", format, value_size_bits,
            LYPLG_LYB_SIZE_VARIABLE_BYTES, 0, &value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* check hints */
    ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* length restriction of the string */
    if (type_str->length) {
        /* value_size is in bytes, but we need number of characters here */
        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_size), value, value_size, err);
        LY_CHECK_GOTO(ret, cleanup);
    }

    /* pattern restrictions */
    ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    /* parse instance-identifier keys, with optional prefix even though it should be mandatory */
    if (value_size && (((char *)value)[0] != '[')) {
        ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid first character '%c', list key predicates expected.",
                ((char *)value)[0]);
        goto cleanup;
    }

    /* do not log */
    prev_lo = ly_temp_log_options(&temp_lo);
    ret = ly_path_parse_predicate(ctx, NULL, value_size ? value : "", value_size, LY_PATH_PREFIX_OPTIONAL,
            LY_PATH_PRED_KEYS, &val->keys);
    ly_temp_log_options(prev_lo);
    if (ret) {
        eitem = ly_err_last(ctx);
        ret = ly_err_new(err, ret, LYVE_DATA, eitem->data_path, NULL, "%s", eitem->msg);
        ly_err_clean((struct ly_ctx *)ctx, NULL);
        goto cleanup;
    }
    val->ctx = ctx;

    /* store format-specific data and context for later prefix resolution */
    ret = lyplg_type_prefix_data_new(ctx, value, value_size, format, prefix_data, &val->format, &val->prefix_data);
    LY_CHECK_GOTO(ret, cleanup);

    switch (format) {
    case LY_VALUE_CANON:
    case LY_VALUE_JSON:
    case LY_VALUE_LYB:
    case LY_VALUE_STR_NS:
        /* store canonical value */
        if (options & LYPLG_TYPE_STORE_DYNAMIC) {
            ret = lydict_insert_zc(ctx, (char *)value, &storage->_canonical);
            options &= ~LYPLG_TYPE_STORE_DYNAMIC;
            LY_CHECK_GOTO(ret, cleanup);
        } else {
            ret = lydict_insert(ctx, value_size ? value : "", value_size, &storage->_canonical);
            LY_CHECK_GOTO(ret, cleanup);
        }
        break;
    case LY_VALUE_SCHEMA:
    case LY_VALUE_SCHEMA_RESOLVED:
    case LY_VALUE_XML:
        /* JSON format with prefix is the canonical one */
        ret = instanceid_keys_print_value(val, LY_VALUE_JSON, NULL, &canon, err);
        LY_CHECK_GOTO(ret, cleanup);

        ret = lydict_insert_zc(ctx, canon, &storage->_canonical);
        LY_CHECK_GOTO(ret, cleanup);
        break;
    }

cleanup:
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        free((void *)value);
    }

    if (ret) {
        lyplg_type_free_xpath10(ctx, storage);
    const void *value = NULL;
    ly_bool dynamic = 0;
    LY_VALUE_FORMAT format;
    void *prefix_data;
    uint32_t value_size_bits, opts = 0, ti;
    struct lyplg_type *type_plg;

    *err = NULL;

    if (subvalue->format == LY_VALUE_LYB) {
        lyb_parse_union(subvalue->original, subvalue->orig_size_bits, &ti, &value, &value_size_bits);
        if (ti != type_idx) {
            /* value of another type, first store the value properly and then use its JSON value for parsing */
            type_plg = LYSC_GET_TYPE_PLG(type_u->types[ti]->plugin_ref);
            rc = type_plg->store(ctx, type_u->types[ti], value, value_size_bits,
                    LYPLG_TYPE_STORE_ONLY, subvalue->format, subvalue->prefix_data, subvalue->hints,
                    subv
</output_head>
<elided_chars>
2821 characters elided
</elided_chars>
<output_tail>
      ret = lyb_fill_subvalue(ctx, type_u, value, value_size_bits, prefix_data, subvalue, &options, unres, err);
        LY_CHECK_GOTO((ret != LY_SUCCESS) && (ret != LY_EINCOMPLETE), cleanup);
    } else {
        /* to correctly resolve the union type, we need to always validate the value */
        options &= ~LYPLG_TYPE_STORE_ONLY;

        /* store value to subvalue */
        ret = union_subvalue_assignment(value, value_size_bits, &subvalue->original, &subvalue->orig_size_bits, &options);
        LY_CHECK_GOTO(ret, cleanup);

        /* store format-specific data for later prefix resolution */
        ret = lyplg_type_prefix_data_new(ctx, value, LYPLG_BITS2BYTES(value_size_bits), format, prefix_data,
                &subvalue->format, &subvalue->prefix_data);
        LY_CHECK_GOTO(ret, cleanup);

        /* use the first usable subtype to store the value */
        ret = union_find_type(ctx, type_u, subvalue, options, 0, NULL, NULL, NULL, NULL, unres, err);
        LY_CHECK_GOTO((ret != LY_SUCCESS) && (ret != LY_EINCOMPLETE), cleanup);
    }

    /* store canonical value, if any (use the specific type value) */
    r = lydict_insert(ctx, subvalue->value._canonical, 0, &storage->_canonical);
    LY_CHECK_ERR_GOTO(r, ret = r, cleanup);

cleanup:
    if (options & LYPLG_TYPE_STORE_DYNAMIC) {
        free((void *)value);
    }

    if ((ret != LY_SUCCESS) && (ret != LY_EINCOMPLETE)) {
        lyplg_type_free_union(ctx, storage);
    }
    return ret;
}

static LY_ERR
lyplg_type_validate_union(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *ctx_node,
        const struct lyd_node *tree, const struct lysc_ext_instance *top_ext, struct lyd_value *storage,
        struct ly_err_item **err)
{
    LY_ERR rc = LY_SUCCESS;
    struct lysc_type_union *type_u = (struct lysc_type_union *)type;
    struct lyd_value_union *subvalue = storage->subvalue;
    struct lyd_value orig = {0};
    uint32_t type_idx;
    ly_bool validated = 0;
    struct lyplg_type *subvalue_type_plg;

    *err = NULL;
lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
        const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext),
        struct lyd_value *storage, struct ly_err_item **err)
{
    LY_ERR ret;
    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
    const void *value;
    size_t value_len;

    LY_CHECK_ARG_RET(NULL, type, storage, err, LY_EINVAL);
    value = lyd_value_get_canonical(ctx, storage);
    value_len = strlen(value);
    *err = NULL;

    /* length restriction of the string */
    if (type_str->length) {
        /* value_len is in bytes, but we need number of characters here */
        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
        LY_CHECK_RET(ret);
    }

    /* pattern restrictions */
    ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_len, err);
    LY_CHECK_RET(ret);

    return LY_SUCCESS;
}

/**
 * @brief Plugin information for string type implementation.
 *
 * Note that external plugins are supposed to use:
 *
 *   LYPLG_TYPES = {
 */
const struct lyplg_type_record plugins_string[] = {
    {
        .module = "",
        .revision = NULL,
        .name = LY_TYPE_STRING_STR,

        .plugin.id = "ly2 string",
        .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes,
        .plugin.store = lyplg_type_store_string,
        .plugin.validate = lyplg_type_validate_string,
        .plugin.compare = lyplg_type_compare_simple,
lyplg_type_store_ipv6_prefix(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits,
        uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints,
        const struct lysc_node *UNUSED(ctx_node), const struct lysc_ext_instance *UNUSED(top_ext),
        struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
{
    LY_ERR ret = LY_SUCCESS;
    struct lyd_value_ipv6_prefix *val;
    uint32_t value_size;

    /* init storage */
    memset(storage, 0, sizeof *storage);
    storage->realtype = type;

    /* check value length */
    ret = lyplg_type_check_value_size("ipv6-prefix", format, value_size_bits, LYPLG_LYB_SIZE_FIXED_BITS,
            LYPLG_IPV6PREF_LYB_VALUE_SIZE, &value_size, err);
    LY_CHECK_GOTO(ret, cleanup);

    if (format == LY_VALUE_LYB) {
        /* validation */
        if (((uint8_t *)value)[16] > 128) {
            ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid LYB ipv6-prefix prefix length %" PRIu8 ".",
                    ((uint8_t *)value)[16]);
            goto cleanup;
        }

        /* store/allocate value */
        if ((options & LYPLG_TYPE_STORE_DYNAMIC) && LYPLG_TYPE_VAL_IS_DYN(val)) {
            storage->dyn_mem = (void *)value;
            options &= ~LYPLG_TYPE_STORE_DYNAMIC;


</output_tail>

Model

THOUGHT: I’ll reuse the core string validation callback for hex-string, rather than duplicate its length and pattern logic. This preserves constraint checking while making the registered callback available to the framework.

▸bash{
{
  "command": "cd /testbed && head -70 src/plugins_internal.h && tail -35 src/plugins_internal.h && grep -n 'lyplg_type_validate_string' src/plugins_types/string.c && grep -n 'plugin.validate' src/plugins_types/hex_string.c"
}
Turn 19evr/openai/gpt-6.1-terra@medium53,763 in · 892 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
/**
 * @file plugins_internal.h
 * @author Radek Krejci <rkrejci@cesnet.cz>
 * @author Michal Vasko <mvasko@cesnet.cz>
 * @brief internal functions to support extension and type plugins.
 *
 * Copyright (c) 2019-2024 CESNET, z.s.p.o.
 *
 * This source code is licensed under BSD 3-Clause License (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/BSD-3-Clause
 */

#ifndef LY_PLUGINS_INTERNAL_H_
#define LY_PLUGINS_INTERNAL_H_

#include <stdint.h>

#include "plugins.h"
#include "plugins_exts.h"
#include "plugins_types.h"

#define LY_TYPE_UNKNOWN_STR "unknown"               /**< text representation of ::LY_TYPE_UNKNOWN */
#define LY_TYPE_BINARY_STR "binary"                 /**< text representation of ::LY_TYPE_BINARY */
#define LY_TYPE_UINT8_STR "8bit unsigned integer"   /**< text representation of ::LY_TYPE_UINT8 */
#define LY_TYPE_UINT16_STR "16bit unsigned integer" /**< text representation of ::LY_TYPE_UINT16 */
#define LY_TYPE_UINT32_STR "32bit unsigned integer" /**< text representation of ::LY_TYPE_UINT32 */
#define LY_TYPE_UINT64_STR "64bit unsigned integer" /**< text representation of ::LY_TYPE_UINT64 */
#define LY_TYPE_STRING_STR "string"                 /**< text representation of ::LY_TYPE_STRING */
#define LY_TYPE_BITS_STR "bits"                     /**< text representation of ::LY_TYPE_BITS */
#define LY_TYPE_BOOL_STR "boolean"                  /**< text representation of ::LY_TYPE_BOOL */
#define LY_TYPE_DEC64_STR "decimal64"               /**< text representation of ::LY_TYPE_DEC64 */
#define LY_TYPE_EMPTY_STR "empty"                   /**< text representation of ::LY_TYPE_EMPTY */
#define LY_TYPE_ENUM_STR "enumeration"              /**< text representation of ::LY_TYPE_ENUM */
#define LY_TYPE_IDENT_STR "identityref"             /**< text representation of ::LY_TYPE_IDENT */
#define LY_TYPE_INST_STR "instance-identifier"      /**< text representation of ::LY_TYPE_INST */
#define LY_TYPE_LEAFREF_STR "leafref"               /**< text representation of ::LY_TYPE_LEAFREF */
#define LY_TYPE_UNION_STR "union"                   /**< text representation of ::LY_TYPE_UNION */
#define LY_TYPE_INT8_STR "8bit integer"             /**< text representation of ::LY_TYPE_INT8 */
#define LY_TYPE_INT16_STR "16bit integer"           /**< text representation of ::LY_TYPE_INT16 */
#define LY_TYPE_INT32_STR "32bit integer"           /**< text representation of ::LY_TYPE_INT32 */
#define LY_TYPE_INT64_STR "64bit integer"           /**< text representation of ::LY_TYPE_INT64 */

/**
 * @brief Shared (= not context specific) type plugins set.
 */
extern struct ly_set ly_plugins_types;

/**
 * @brief Shared (= not context specific) extension plugins set.
 */
extern struct ly_set ly_plugins_extensions;

/**
 * @brief Count of static type plugins.
 */
extern uint32_t ly_static_type_plugins_count;

/**
 * @brief Count of static extension plugins.
 */
extern uint32_t ly_static_ext_plugins_count;

/**
 * @brief Get a type plugin.
 *
 * @param[in] PLUGIN_REF Reference to a type plugin. Either an index of a static plugin (offset by +1)
 * or a pointer to an external plugin.
LY_ERR lyplg_init(ly_bool builtin_type_plugins_only, ly_bool static_plugins_only);

/**
 * @brief Remove (unload) all the plugins currently available.
 */
void lyplg_clean(void);

/**
 * @brief Find a type plugin.
 *
 * @param[in] ctx Optional context for which the plugin should be find. If NULL, only shared plugins will be searched
 * @param[in] module Name of the module where the type is defined. Must not be NULL, in case of plugins for
 * built-in types, the module is "".
 * @param[in] revision Revision of the module for which the plugin is implemented. NULL is not a wildcard, it matches
 * only the plugins with NULL revision specified.
 * @param[in] name Name of the type which the plugin implements.
 * @return ID of the found type plugin, 0 if none found. The type plugin can be obtained
 * by passing the returned ID to ::lysc_get_type_plugin() or ::LYSC_GET_TYPE_PLG.
 */
uintptr_t lyplg_type_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name);

/**
 * @brief Find an extension plugin.
 *
 * @param[in] ctx Optional context for which the plugin should be find. If NULL, only shared plugins will be searched
 * @param[in] module Name of the module where the extension is defined.
 * @param[in] revision Revision of the module for which the plugin is implemented. NULL is not a wildcard, it matches
 * only the plugins with NULL revision specified.
 * @param[in] name Name of the extension which the plugin implements.
 * @return ID of the found extension plugin, 0 if none found. The extension plugin can be obtained
 * by passing the returned ID to ::lysc_get_ext_plugin() or ::LYSC_GET_EXT_PLG.
 */
uintptr_t lyplg_ext_plugin_find(const struct ly_ctx *ctx, const char *module, const char *revision, const char *name);

#endif /* LY_PLUGINS_INTERNAL_H_ */
37:static LY_ERR lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type,
106:        ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err);
125:lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
169:        .plugin.validate = lyplg_type_validate_string,
130:        .plugin.validate = NULL,
145:        .plugin.validate = NULL,
160:        .plugin.validate = NULL,
175:        .plugin.validate = NULL,
</output>

Model

THOUGHT: The shared callback can also replace the inline checks in instance-identifier-keys. I’ll register it for both plugins and invoke it after canonical storage, matching the core string plugin’s pattern.

▸bash{
{
  "command": "cd /testbed && perl -0777 -i -pe 's@/\\*\\*\\n \\* \\@brief Shared \\(= not context specific\\) type plugins set\\.@/**\\n * \\@brief Validate string length and pattern restrictions for a stored value.\\n */\\nLY_ERR lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type,\\n        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,\\n        struct lyd_value *storage, struct ly_err_item **err);\\n\\n/**\\n * \\@brief Shared (= not context specific) type plugins set.@' src/plugins_internal.h\nperl -0777 -i -pe 's/static LY_ERR lyplg_type_validate_string\\(const struct ly_ctx \\*ctx, const struct lysc_type \\*type,\\n        const struct lyd_node \\*ctx_node, const struct lyd_node \\*tree, const struct lysc_ext_instance \\*top_ext,\\n        struct lyd_value \\*storage, struct ly_err_item \\*\\*err\\);\\n\\n//; s/static LY_ERR\\n(?=lyplg_type_validate_string\\()/LY_ERR\\n/' src/plugins_types/string.c\nperl -0777 -i -pe 's/    struct lysc_type_str \\*type_str = \\(struct lysc_type_str \\*\\)type;\\n//; s/    if \\(!\\(options & LYPLG_TYPE_STORE_ONLY\\)\\) \\{\\n        \\/\\* validate length restriction of the string \\*\\/.*?\\n    \\}/    if (!(options \\& LYPLG_TYPE_STORE_ONLY)) {\\n        ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err);\\n        LY_CHECK_GOTO(ret, cleanup);\\n    }/s; s/\\.plugin\\.validate = NULL/\\.plugin.validate = lyplg_type_validate_string/g' src/plugins_types/hex_string.c\nperl -0777 -i -pe 's/    struct lysc_type_str \\*type_str = \\(struct lysc_type_str \\*\\)type;\\n//; s/    \\/\\* length restriction of the string \\*\\/\\n.*?    \\/\\* pattern restrictions \\*\\/\\n.*?    LY_CHECK_GOTO\\(ret, cleanup\\);\\n\\n//s; s/(        break;\\n    \\}\\n)(\\ncleanup:)/$1\\n    if (!(options \\& LYPLG_TYPE_STORE_ONLY)) {\\n        ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err);\\n        LY_CHECK_GOTO(ret, cleanup);\\n    }\\n$2/s; s/\\.plugin\\.validate = NULL/\\.plugin.validate = lyplg_type_validate_string/g' src/plugins_types/instanceid_keys.c\ncmake --build build -j4 > /tmp/libyang-build3.log 2>&1; tail -35 /tmp/libyang-build3.log; grep -n 'warning:\\|error:' /tmp/libyang-build3.log | head -30",
  "timeout": 120000
}
Turn 20evr/openai/gpt-6.1-terra@medium55,604 in · 121 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
[ 15%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/empty.c.o
[ 16%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/enumeration.c.o
[ 16%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/identityref.c.o
[ 17%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/instanceid.c.o
[ 17%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/instanceid_keys.c.o
/testbed/src/plugins_types/instanceid_keys.c: In function ‘lyplg_type_store_instanceid_keys’:
/testbed/src/plugins_types/instanceid_keys.c:213:15: warning: implicit declaration of function ‘lyplg_type_validate_string’; did you mean ‘lyplg_type_validate_range’? [-Wimplicit-function-declaration]
  213 |         ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |               lyplg_type_validate_range
[ 17%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/integer.c.o
[ 18%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/leafref.c.o
/testbed/src/plugins_types/instanceid_keys.c: At top level:
/testbed/src/plugins_types/instanceid_keys.c:244:28: error: ‘lyplg_type_validate_string’ undeclared here (not in a function); did you mean ‘lyplg_type_validate_range’?
  244 |         .plugin.validate = lyplg_type_validate_string,
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                            lyplg_type_validate_range
gmake[2]: *** [CMakeFiles/yangobj.dir/build.make:902: CMakeFiles/yangobj.dir/src/plugins_types/instanceid_keys.c.o] Error 1
gmake[2]: *** Waiting for unfinished jobs....
[ 19%] Building C object CMakeFiles/yangobj.dir/src/plugins_types/string.c.o
/testbed/src/plugins_types/string.c: In function ‘lyplg_type_store_string’:
/testbed/src/plugins_types/string.c:102:15: warning: implicit declaration of function ‘lyplg_type_validate_string’; did you mean ‘lyplg_type_validate_range’? [-Wimplicit-function-declaration]
  102 |         ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |               lyplg_type_validate_range
/testbed/src/plugins_types/string.c: At top level:
/testbed/src/plugins_types/string.c:121:1: error: conflicting types for ‘lyplg_type_validate_string’; have ‘LY_ERR(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, const struct lysc_ext_instance *, struct lyd_value *, struct ly_err_item **)’
  121 | lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
/testbed/src/plugins_types/string.c:102:15: note: previous implicit declaration of ‘lyplg_type_validate_string’ with type ‘int()’
  102 |         ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err);
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~
gmake[2]: *** [CMakeFiles/yangobj.dir/build.make:958: CMakeFiles/yangobj.dir/src/plugins_types/string.c.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:396: CMakeFiles/yangobj.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
41:/testbed/src/plugins_types/instanceid_keys.c:213:15: warning: implicit declaration of function ‘lyplg_type_validate_string’; did you mean ‘lyplg_type_validate_range’? [-Wimplicit-function-declaration]
48:/testbed/src/plugins_types/instanceid_keys.c:244:28: error: ‘lyplg_type_validate_string’ undeclared here (not in a function); did you mean ‘lyplg_type_validate_range’?
56:/testbed/src/plugins_types/string.c:102:15: warning: implicit declaration of function ‘lyplg_type_validate_string’; did you mean ‘lyplg_type_validate_range’? [-Wimplicit-function-declaration]
61:/testbed/src/plugins_types/string.c:121:1: error: conflicting types for ‘lyplg_type_validate_string’; have ‘LY_ERR(const struct ly_ctx *, const struct lysc_type *, const struct lyd_node *, const struct lyd_node *, const struct lysc_ext_instance *, struct lyd_value *, struct ly_err_item **)’
</output>

Model

THOUGHT: The build indicates the shared declaration was not inserted or included as intended. I’ll correct the internal header and required include, then rebuild.

▸bash{
{
  "command": "cd /testbed && grep -n 'validate_string\\|Shared' src/plugins_internal.h; head -40 src/plugins_types/instanceid_keys.c; git diff -- src/plugins_types/instanceid_keys.c | head -120"
}
Turn 21evr/openai/gpt-6.1-terra@medium56,736 in · 289 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
47: * @brief Shared (= not context specific) type plugins set.
52: * @brief Shared (= not context specific) extension plugins set.
/**
 * @file instanceid_keys.c
 * @author Michal Vasko <mvasko@cesnet.cz>
 * @brief ietf-netconf edit-config key metadata instance-identifier keys predicate type plugin.
 *
 * Copyright (c) 2022 - 2025 CESNET, z.s.p.o.
 *
 * This source code is licensed under BSD 3-Clause License (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/BSD-3-Clause
 */
#define _GNU_SOURCE /* strdup */

#include "plugins_types.h"

#include <stdint.h>
#include <stdlib.h>

#include "libyang.h"

/* additional internal headers for some useful simple macros */
#include "compat.h"
#include "ly_common.h"
#include "path.h"
#include "plugins_internal.h" /* LY_TYPE_*_STR */
#include "xpath.h"

/**
 * @page howtoDataLYB LYB Binary Format
 * @subsection howtoDataLYBTypesInstanceIdentifierKeys instance-identifier-keys (yang)
 *
 * | Size (b) | Mandatory | Type | Meaning |
 * | :------  | :-------: | :--: | :-----: |
 * | variable, full bytes | yes | `char *` | string JSON format of the instance-identifier keys predicate |
 */

/**
 * @brief Special lyd_value structure for yang instance-identifier-keys values.
diff --git a/src/plugins_types/instanceid_keys.c b/src/plugins_types/instanceid_keys.c
index 5d240fcfc..d4d96c103 100644
--- a/src/plugins_types/instanceid_keys.c
+++ b/src/plugins_types/instanceid_keys.c
@@ -138,7 +138,6 @@ lyplg_type_store_instanceid_keys(const struct ly_ctx *ctx, const struct lysc_typ
         struct ly_err_item **err)
 {
     LY_ERR ret = LY_SUCCESS;
-    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
     struct lyd_value_instance_identifier_keys *val;
     uint32_t value_size, *prev_lo, temp_lo = LY_LOSTORE;
     const struct ly_err_item *eitem;
@@ -159,17 +158,6 @@ lyplg_type_store_instanceid_keys(const struct ly_ctx *ctx, const struct lysc_typ
     ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
     LY_CHECK_GOTO(ret, cleanup);
 
-    /* length restriction of the string */
-    if (type_str->length) {
-        /* value_size is in bytes, but we need number of characters here */
-        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_size), value, value_size, err);
-        LY_CHECK_GOTO(ret, cleanup);
-    }
-
-    /* pattern restrictions */
-    ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
-    LY_CHECK_GOTO(ret, cleanup);
-
     /* parse instance-identifier keys, with optional prefix even though it should be mandatory */
     if (value_size && (((char *)value)[0] != '[')) {
         ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid first character '%c', list key predicates expected.",
@@ -221,6 +209,11 @@ lyplg_type_store_instanceid_keys(const struct ly_ctx *ctx, const struct lysc_typ
         break;
     }
 
+    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
+        ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err);
+        LY_CHECK_GOTO(ret, cleanup);
+    }
+
 cleanup:
     if (options & LYPLG_TYPE_STORE_DYNAMIC) {
         free((void *)value);
@@ -248,7 +241,7 @@ const struct lyplg_type_record plugins_instanceid_keys[] = {
         .plugin.id = "ly2 instance-identifier-keys",
         .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes,
         .plugin.store = lyplg_type_store_instanceid_keys,
-        .plugin.validate = NULL,
+        .plugin.validate = lyplg_type_validate_string,
         .plugin.compare = lyplg_type_compare_simple,
         .plugin.sort = lyplg_type_sort_simple,
         .plugin.print = lyplg_type_print_xpath10,
</output>

Model

THOUGHT: The files already include the internal header; the declaration insertion simply didn’t match. I’ll insert it directly and rerun the build and relevant tests.

▸bash{
{
  "command": "cd /testbed && sed -i '/#define LY_TYPE_UNKNOWN_STR/i\\/* Shared string restriction validation callback. */\\nLY_ERR lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type,\\n        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,\\n        struct lyd_value *storage, struct ly_err_item **err);\\n' src/plugins_internal.h\ncmake --build build -j4 > /tmp/libyang-build4.log 2>&1 && /tmp/libyang-pr-check && cd build && ctest --output-on-failure -j4 > /tmp/libyang-ctest2.log 2>&1; tail -20 /tmp/libyang-ctest2.log; grep -n 'warning:\\|error:' /tmp/libyang-build4.log | head -25",
  "timeout": 120000
}
Turn 22evr/openai/gpt-6.1-terra@medium57,358 in · 593 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
rc=3 expected=3 message=Missing date-and-time fractions after '.'. path=/a:l
      Start  1: utest_uint8
54/60 Test  #4: utest_uint64 ......................   Passed    0.06 sec
      Start 52: utest_metadata
55/60 Test  #3: utest_uint32 ......................   Passed    0.06 sec
      Start 16: utest_instanceid_keys
56/60 Test  #2: utest_uint16 ......................   Passed    0.06 sec
      Start 35: utest_yanglib
57/60 Test  #1: utest_uint8 .......................   Passed    0.01 sec
58/60 Test #52: utest_metadata ....................   Passed    0.01 sec
59/60 Test #16: utest_instanceid_keys .............   Passed    0.01 sec
60/60 Test #35: utest_yanglib .....................   Passed    0.01 sec

97% tests passed, 2 tests failed out of 60

Total Test time (real) =   1.16 sec

The following tests FAILED:
	 13 - utest_yang_types (Failed)
	 55 - utest_schema_mount (Failed)
Errors while running CTest
48:/testbed/src/plugins_types/ipv4_address.c:129:27: warning: unused variable ‘type_str’ [-Wunused-variable]
54:/testbed/src/plugins_types/ipv6_address.c:130:27: warning: unused variable ‘type_str’ [-Wunused-variable]
</output>

Model

THOUGHT: The build and regression suite now show only the two legacy expectation failures. I’ll exercise valid and invalid hex strings and both IP prefix parsers with a temporary schema, including missing and out-of-range prefixes.

▸bash{
{
  "command": "cat > /tmp/pr-types.yang <<'EOF'\nmodule pr-types {\n  yang-version 1.1; namespace \"urn:pr-types\"; prefix p;\n  import ietf-yang-types { prefix yang; }\n  import ietf-inet-types { prefix inet; }\n  leaf hex { type yang:hex-string; }\n  leaf p4 { type inet:ipv4-prefix; }\n  leaf p6 { type inet:ipv6-prefix; }\n}\nEOF\ncd /testbed && for x in 'hex|AA:12' 'hex|zz' 'p4|192.0.2.1/24' 'p4|192.0.2.1' 'p4|192.0.2.1/33' 'p4|192.0.2.1/' 'p6|2001:db8::1/64' 'p6|2001:db8::1' 'p6|2001:db8::1/129'; do n=${x%%|*}; v=${x#*|}; printf '<%s xmlns=\"urn:pr-types\">%s</%s>' \"$n\" \"$v\" \"$n\" > /tmp/pr-value.xml; build/yanglint /tmp/pr-types.yang /tmp/pr-value.xml >/tmp/pr-output 2>&1; printf '%-28s rc=%s ' \"$x\" \"$?\"; head -1 /tmp/pr-output; done\n git diff --check && git status --short",
  "timeout": 120000
}
Turn 23evr/openai/gpt-6.1-terra@medium58,227 in · 470 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
hex|AA:12                    rc=0 hex|zz                       rc=1 libyang err : Unsatisfied pattern - "zz" does not conform to "([0-9a-fA-F]{2}(:[0-9a-fA-F]{2})*)?". (/pr-types:hex) (line 1)
p4|192.0.2.1/24              rc=0 p4|192.0.2.1                 rc=1 libyang err : Invalid IPv4 prefix "192.0.2.1". (/pr-types:p4) (line 1)
p4|192.0.2.1/33              rc=1 libyang err : Invalid IPv4 prefix "192.0.2.1/33". (/pr-types:p4) (line 1)
p4|192.0.2.1/                rc=1 libyang err : Invalid IPv4 prefix "192.0.2.1/". (/pr-types:p4) (line 1)
p6|2001:db8::1/64            rc=0 p6|2001:db8::1               rc=1 libyang err : Invalid IPv6 prefix "2001:db8::1". (/pr-types:p6) (line 1)
p6|2001:db8::1/129           rc=1 libyang err : Invalid IPv6 prefix "2001:db8::1/129". (/pr-types:p6) (line 1)
 M src/plugins_internal.h
 M src/plugins_types/binary.c
 M src/plugins_types/date_and_time.c
 M src/plugins_types/decimal64.c
 M src/plugins_types/hex_string.c
 M src/plugins_types/instanceid_keys.c
 M src/plugins_types/integer.c
 M src/plugins_types/ipv4_address_no_zone.c
 M src/plugins_types/ipv4_prefix.c
 M src/plugins_types/ipv6_address_no_zone.c
 M src/plugins_types/ipv6_prefix.c
 M src/plugins_types/string.c
 M src/plugins_types/xpath1.0.c
?? build/
</output>

Model

THOUGHT: The edge checks pass, including rejection of invalid hex and malformed prefixes. I’ll do a final review of the source diff and test results before creating the requested patch.

▸bash{
{
  "command": "cd /testbed && git diff --stat && git diff -- src/plugins_internal.h src/plugins_types/{hex_string,instanceid_keys,string,decimal64}.c && git diff --check && grep -A13 'utest_yang_types.*Failed' /tmp/libyang-ctest2.log | head -13 && grep -A18 'test_xpath$' /tmp/libyang-ctest2.log | tail -12",
  "timeout": 120000
}
Turn 24evr/openai/gpt-6.1-terra@medium61,243 in · 219 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<warning>
The output of your last command was too long.
Please try a different command that produces less output.
If you're looking at a file you can try use head, tail or sed to view a smaller number of lines selectively.
If you're using grep or find and it produced too much output, you can use a more selective search pattern.
If you really need to see something from the full command's output, you can redirect output to a file and then search in that file.
</warning><output_head>
 src/plugins_internal.h                   |  5 +++++
 src/plugins_types/binary.c               |  9 +++++----
 src/plugins_types/date_and_time.c        | 11 -----------
 src/plugins_types/decimal64.c            | 10 ++++++----
 src/plugins_types/hex_string.c           | 31 +++++--------------------------
 src/plugins_types/instanceid_keys.c      | 19 ++++++-------------
 src/plugins_types/integer.c              | 18 ++++++++++--------
 src/plugins_types/ipv4_address_no_zone.c | 12 ------------
 src/plugins_types/ipv4_prefix.c          | 16 +++++-----------
 src/plugins_types/ipv6_address_no_zone.c |  1 -
 src/plugins_types/ipv6_prefix.c          |  8 +++++---
 src/plugins_types/string.c               | 12 +++++-------
 src/plugins_types/xpath1.0.c             | 12 ------------
 13 files changed, 52 insertions(+), 112 deletions(-)
diff --git a/src/plugins_internal.h b/src/plugins_internal.h
index 29ffbfada..0f2c3c041 100644
--- a/src/plugins_internal.h
+++ b/src/plugins_internal.h
@@ -22,6 +22,11 @@
 #include "plugins_exts.h"
 #include "plugins_types.h"
 
+/* Shared string restriction validation callback. */
+LY_ERR lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type,
+        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,
+        struct lyd_value *storage, struct ly_err_item **err);
+
 #define LY_TYPE_UNKNOWN_STR "unknown"               /**< text representation of ::LY_TYPE_UNKNOWN */
 #define LY_TYPE_BINARY_STR "binary"                 /**< text representation of ::LY_TYPE_BINARY */
 #define LY_TYPE_UINT8_STR "8bit unsigned integer"   /**< text representation of ::LY_TYPE_UINT8 */
diff --git a/src/plugins_types/decimal64.c b/src/plugins_types/decimal64.c
index fe77f2278..d4c9ff9df 100644
--- a/src/plugins_types/decimal64.c
+++ b/src/plugins_types/decimal64.c
@@ -34,7 +34,9 @@
  * | 64        | yes | `int64_t *` | little-endian value represented without floating point |
  */
 
-static LY_ERR lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err);
+static LY_ERR lyplg_type_validate_decimal64(const struct ly_ctx *ctx, const struct lysc_type *type,
+        const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext,
+        struct lyd_value *storage, struct ly_err_item **err);
 
 /**
  * @brief Convert decimal64 number to canonical string.
@@ -151,7 +153,7 @@ lyplg_type_store_decimal64(const struct ly_ctx *ctx, const struct lysc_type *typ
 
     if (!(options & LYPLG_TYPE_STORE_ONLY)) {
         /* validate value */
-        ret = lyplg_type_validate_decimal64(ctx, type, NULL, NULL, storage, err);
+        ret = lyplg_type_validate_decimal64(ctx, type, NULL, NULL, NULL, storage, err);
         LY_CHECK_GOTO(ret, cleanup);
     }
 
@@ -166,13 +168,13 @@ cleanup:
     return ret;
 }
 
-static LY_ERR
 /**
  * @brief Implementation of ::lyplg_type_validate_clb for the built-in decimal64 type.
  */
 static LY_ERR
 lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
-        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
+        const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext),
+        struct lyd_value *storage, struct ly_err_item **err)
 {
     LY_ERR ret;
     struct lysc_type_dec *type_dec = (struct lysc_type_dec *)type;
diff --git a/src/plugins_types/hex_string.c b/src/plugins_types/hex_string.c
index dd97dc177..19f23474c 100644
--- a/src/plugins_types/hex_string.c
+++ b/src/plugins_types/hex_string.c
@@ -44,7 +44,6 @@ lyplg_type_store_hex_string(const struct ly_ctx *ctx, const struct lysc_type *ty
         struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
 {
     LY_ERR ret = LY_SUCCESS;
-    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
     uint32_t value_size, i;
 
     /* init storage */
@@ -60,17 +59,6 @@ lyplg_type_store_hex_string(const struct ly_ctx *ctx, const struct lysc_type *ty
     ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err);
     LY_CHECK_GOTO(ret, cleanup);
 
-    /* length restriction of the string */
-    if (type_str->length) {
-        /* value_len is in bytes, but we need number of characters here */
-        ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err);
-        LY_CHECK_GOTO(ret, cleanup);
-    }
-
-    /* pattern restrictions */
-    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
-    LY_CHECK_GOTO(ret, cleanup);
-
     /* make a copy, it is needed for canonization */
     if ((format != LY_VALUE_CANON) && !(options & LYPLG_TYPE_STORE
</output_head>
<elided_chars>
3751 characters elided
</elided_chars>
<output_tail>
 = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_size), value, value_size, err);
-        LY_CHECK_GOTO(ret, cleanup);
-    }
-
-    /* pattern restrictions */
-    ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err);
-    LY_CHECK_GOTO(ret, cleanup);
-
     /* parse instance-identifier keys, with optional prefix even though it should be mandatory */
     if (value_size && (((char *)value)[0] != '[')) {
         ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid first character '%c', list key predicates expected.",
@@ -221,6 +209,11 @@ lyplg_type_store_instanceid_keys(const struct ly_ctx *ctx, const struct lysc_typ
         break;
     }
 
+    if (!(options & LYPLG_TYPE_STORE_ONLY)) {
+        ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err);
+        LY_CHECK_GOTO(ret, cleanup);
+    }
+
 cleanup:
     if (options & LYPLG_TYPE_STORE_DYNAMIC) {
         free((void *)value);
@@ -248,7 +241,7 @@ const struct lyplg_type_record plugins_instanceid_keys[] = {
         .plugin.id = "ly2 instance-identifier-keys",
         .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes,
         .plugin.store = lyplg_type_store_instanceid_keys,
-        .plugin.validate = NULL,
+        .plugin.validate = lyplg_type_validate_string,
         .plugin.compare = lyplg_type_compare_simple,
         .plugin.sort = lyplg_type_sort_simple,
         .plugin.print = lyplg_type_print_xpath10,
diff --git a/src/plugins_types/string.c b/src/plugins_types/string.c
index 90c64b98b..99b12cf10 100644
--- a/src/plugins_types/string.c
+++ b/src/plugins_types/string.c
@@ -34,8 +34,6 @@
  * | variable, full bytes | yes | `char *` | string itself |
  */
 
-static LY_ERR lyplg_type_validate_string(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err);
-
 /**
  * @brief Check string value for invalid characters.
  *
@@ -66,7 +64,6 @@ lyplg_type_store_string(const struct ly_ctx *ctx, const struct lysc_type *type,
         struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
 {
     LY_ERR ret = LY_SUCCESS;
-    struct lysc_type_str *type_str = (struct lysc_type_str *)type;
     uint32_t value_size;
 
     /* init storage */
@@ -102,7 +99,7 @@ lyplg_type_store_string(const struct ly_ctx *ctx, const struct lysc_type *type,
 
     if (!(options & LYPLG_TYPE_STORE_ONLY)) {
         /* validate value */
-        ret = lyplg_type_validate_string(ctx, type, NULL, NULL, storage, err);
+        ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err);
         LY_CHECK_GOTO(ret, cleanup);
     }
 
@@ -120,9 +117,10 @@ cleanup:
 /**
  * @brief Implementation of ::lyplg_type_validate_clb for the string type.
  */
-static LY_ERR
+LY_ERR
 lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node),
-        const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
+        const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext),
+        struct lyd_value *storage, struct ly_err_item **err)
 {
     LY_ERR ret;
     struct lysc_type_str *type_str = (struct lysc_type_str *)type;
@@ -142,7 +140,7 @@ lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *typ
     }
 
     /* pattern restrictions */
-    ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err);
+    ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_len, err);
     LY_CHECK_RET(ret);
 
     return LY_SUCCESS;
 1/60 Test #13: utest_yang_types ..................***Failed    0.02 sec
[==========] Running 5 test(s).
[ RUN      ] test_data_xml
ERROR: LY_EVALID != 0x3; MSG: Missing date-and-time fractions after '.'.
Could not run test: [   LINE   ] --- /testbed/tests/utests/types/yang_types.c:114: error: Failure!ly_err_last(current_utest_context->ctx)
[   LINE   ] --- /testbed/tests/utests/types/../utests.h:1351: error: Failure!Test teardown failed
[  ERROR   ] test_data_xml
[ RUN      ] test_print
[       OK ] test_print
[ RUN      ] test_duplicate
[       OK ] test_duplicate
[ RUN      ] test_lyb
[       OK ] test_lyb
16/60 Test #34: utest_xpath .......................   Passed    0.05 sec
      Start 41: utest_tree_data
17/60 Test #49: utest_validation ..................   Passed    0.04 sec
      Start  5: utest_int8
18/60 Test #47: utest_parser_json .................   Passed    0.04 sec
      Start 10: utest_bits
19/60 Test #48: utest_lyb .........................   Passed    0.04 sec
      Start  9: utest_string
20/60 Test #41: utest_tree_data ...................   Passed    0.04 sec
      Start 50: utest_merge
21/60 Test  #5: utest_int8 ........................   Passed    0.03 sec
      Start 29: utest_inout

</output_tail>

Model

THOUGHT: The final review confirms that only source files are changed. The two failing tests assert the old date error and old schema-mount identifier; the actual behavior matches the requested results. I’ll create the submission patch now.

▸bash{
{
  "command": "cd /testbed && git diff -- src/plugins_internal.h src/plugins_types/binary.c src/plugins_types/date_and_time.c src/plugins_types/decimal64.c src/plugins_types/hex_string.c src/plugins_types/instanceid_keys.c src/plugins_types/integer.c src/plugins_types/ipv4_address_no_zone.c src/plugins_types/ipv4_prefix.c src/plugins_types/ipv6_address_no_zone.c src/plugins_types/ipv6_prefix.c src/plugins_types/string.c src/plugins_types/xpath1.0.c > patch.txt"
}
Turn 25evr/openai/gpt-6.1-terra@medium61,446 in · 94 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
</output>

Model

THOUGHT: I’ll verify that the patch contains only the intended source-file headers and no whitespace errors before submission.

▸bash{
{
  "command": "cd /testbed && grep -E '^(diff --git|--- |\\+\\+\\+ )' patch.txt && git apply --check --reverse patch.txt && git diff --check && wc -l patch.txt"
}
Turn 26evr/openai/gpt-6.1-terra@medium62,106 in · 63 out

Tool

▸Result<returncode>0</returncode>
<returncode>0</returncode>
<output>
diff --git a/src/plugins_internal.h b/src/plugins_internal.h
--- a/src/plugins_internal.h
+++ b/src/plugins_internal.h
diff --git a/src/plugins_types/binary.c b/src/plugins_types/binary.c
--- a/src/plugins_types/binary.c
+++ b/src/plugins_types/binary.c
diff --git a/src/plugins_types/date_and_time.c b/src/plugins_types/date_and_time.c
--- a/src/plugins_types/date_and_time.c
+++ b/src/plugins_types/date_and_time.c
diff --git a/src/plugins_types/decimal64.c b/src/plugins_types/decimal64.c
--- a/src/plugins_types/decimal64.c
+++ b/src/plugins_types/decimal64.c
diff --git a/src/plugins_types/hex_string.c b/src/plugins_types/hex_string.c
--- a/src/plugins_types/hex_string.c
+++ b/src/plugins_types/hex_string.c
diff --git a/src/plugins_types/instanceid_keys.c b/src/plugins_types/instanceid_keys.c
--- a/src/plugins_types/instanceid_keys.c
+++ b/src/plugins_types/instanceid_keys.c
diff --git a/src/plugins_types/integer.c b/src/plugins_types/integer.c
--- a/src/plugins_types/integer.c
+++ b/src/plugins_types/integer.c
diff --git a/src/plugins_types/ipv4_address_no_zone.c b/src/plugins_types/ipv4_address_no_zone.c
--- a/src/plugins_types/ipv4_address_no_zone.c
+++ b/src/plugins_types/ipv4_address_no_zone.c
diff --git a/src/plugins_types/ipv4_prefix.c b/src/plugins_types/ipv4_prefix.c
--- a/src/plugins_types/ipv4_prefix.c
+++ b/src/plugins_types/ipv4_prefix.c
diff --git a/src/plugins_types/ipv6_address_no_zone.c b/src/plugins_types/ipv6_address_no_zone.c
--- a/src/plugins_types/ipv6_address_no_zone.c
+++ b/src/plugins_types/ipv6_address_no_zone.c
diff --git a/src/plugins_types/ipv6_prefix.c b/src/plugins_types/ipv6_prefix.c
--- a/src/plugins_types/ipv6_prefix.c
+++ b/src/plugins_types/ipv6_prefix.c
diff --git a/src/plugins_types/string.c b/src/plugins_types/string.c
--- a/src/plugins_types/string.c
+++ b/src/plugins_types/string.c
diff --git a/src/plugins_types/xpath1.0.c b/src/plugins_types/xpath1.0.c
--- a/src/plugins_types/xpath1.0.c
+++ b/src/plugins_types/xpath1.0.c
524 patch.txt
</output>

Model

THOUGHT: The patch is verified and contains only the intended source changes. I’ll submit it now.

▸bash{
{
  "command": "cd /testbed && echo COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT && cat patch.txt"
}

Grading

agent_cost_estimate_usd1.040965
agent_missingfalse
api_calls26
evaluatedtrue
exit_statusSubmitted
golden_resultsuccess
golden_successtrue
idCESNET__libyang-c_8d3d805
languagec
model_patchdiff --git a/src/plugins_internal.h b/src/plugins_internal.h index 29ffbfada..0f2c3c041 100644 --- a/src/plugins_internal.h +++ b/src/plugins_internal.h @@ -22,6 +22,11 @@ #include "plugins_exts.h" #include "plugins_types.h" +/* Shared string restriction validation callback. */ +LY_ERR lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type, + const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext, + struct lyd_value *storage, struct ly_err_item **err); + #define LY_TYPE_UNKNOWN_STR "unknown" /**< text representation of ::LY_TYPE_UNKNOWN */ #define LY_TYPE_BINARY_STR "binary" /**< text representation of ::LY_TYPE_BINARY */ #define LY_TYPE_UINT8_STR "8bit unsigned integer" /**< text representation of ::LY_TYPE_UINT8 */ diff --git a/src/plugins_types/binary.c b/src/plugins_types/binary.c index 1eb3b6872..3a09a7e41 100644 --- a/src/plugins_types/binary.c +++ b/src/plugins_types/binary.c @@ -46,7 +46,8 @@ static const char b64_etable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst static void lyplg_type_free_binary(const struct ly_ctx *ctx, struct lyd_value *value); static LY_ERR lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type, - const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err); + const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext, + struct lyd_value *storage, struct ly_err_item **err); /** * @brief Encode binary value into a base64 string value. @@ -332,7 +333,7 @@ lyplg_type_store_binary(const struct ly_ctx *ctx, const struct lysc_type *type, if (!(options & LYPLG_TYPE_STORE_ONLY)) { /* validate value */ - ret = lyplg_type_validate_binary(ctx, type, NULL, NULL, storage, err); + ret = lyplg_type_validate_binary(ctx, type, NULL, NULL, NULL, storage, err); LY_CHECK_GOTO(ret, cleanup); } @@ -347,13 +348,13 @@ cleanup: return ret; } -static LY_ERR /** * @brief Implementation of ::lyplg_type_validate_clb for the binary type. */ static LY_ERR lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), - const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err) + const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext), + struct lyd_value *storage, struct ly_err_item **err) { struct lysc_type_bin *type_bin = (struct lysc_type_bin *)type; struct lyd_value_binary *val; diff --git a/src/plugins_types/date_and_time.c b/src/plugins_types/date_and_time.c index 4acb63e78..8a09c0550 100644 --- a/src/plugins_types/date_and_time.c +++ b/src/plugins_types/date_and_time.c @@ -53,7 +53,6 @@ lyplg_type_store_date_and_time(const struct ly_ctx *ctx, const struct lysc_type struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; - struct lysc_type_str *type_dat = (struct lysc_type_str *)type; struct lyd_value_date_and_time *val; uint32_t i, value_size; char c; @@ -108,16 +107,6 @@ lyplg_type_store_date_and_time(const struct ly_ctx *ctx, const struct lysc_type ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err); LY_CHECK_GOTO(ret, cleanup); - /* length restriction, there can be only ASCII chars */ - if (type_dat->length) { - ret = lyplg_type_validate_range(LY_TYPE_STRING, type_dat->length, value_len, value, value_len, err); - LY_CHECK_GOTO(ret, cleanup); - } - - /* date-and-time pattern */ - ret = lyplg_type_validate_patterns(type_dat->patterns, value, value_len, err); - LY_CHECK_GOTO(ret, cleanup); - /* convert to UNIX time and fractions of second */ ret = ly_time_str2time(value, &val->time, &val->fractions_s); if (ret) { diff --git a/src/plugins_types/decimal64.c b/src/plugins_types/decimal64.c index fe77f2278..d4c9ff9df 100644 --- a/src/plugins_types/decimal64.c +++ b/src/plugins_types/decimal64.c @@ -34,7 +34,9 @@ * | 64 | yes | `int64_t *` | little-endian value represented without floating point | */ -static LY_ERR lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err); +static LY_ERR lyplg_type_validate_decimal64(const struct ly_ctx *ctx, const struct lysc_type *type, + const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext, + struct lyd_value *storage, struct ly_err_item **err); /** * @brief Convert decimal64 number to canonical string. @@ -151,7 +153,7 @@ lyplg_type_store_decimal64(const struct ly_ctx *ctx, const struct lysc_type *typ if (!(options & LYPLG_TYPE_STORE_ONLY)) { /* validate value */ - ret = lyplg_type_validate_decimal64(ctx, type, NULL, NULL, storage, err); + ret = lyplg_type_validate_decimal64(ctx, type, NULL, NULL, NULL, storage, err); LY_CHECK_GOTO(ret, cleanup); } @@ -166,13 +168,13 @@ cleanup: return ret; } -static LY_ERR /** * @brief Implementation of ::lyplg_type_validate_clb for the built-in decimal64 type. */ static LY_ERR lyplg_type_validate_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), - const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err) + const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext), + struct lyd_value *storage, struct ly_err_item **err) { LY_ERR ret; struct lysc_type_dec *type_dec = (struct lysc_type_dec *)type; diff --git a/src/plugins_types/hex_string.c b/src/plugins_types/hex_string.c index dd97dc177..19f23474c 100644 --- a/src/plugins_types/hex_string.c +++ b/src/plugins_types/hex_string.c @@ -44,7 +44,6 @@ lyplg_type_store_hex_string(const struct ly_ctx *ctx, const struct lysc_type *ty struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; - struct lysc_type_str *type_str = (struct lysc_type_str *)type; uint32_t value_size, i; /* init storage */ @@ -60,17 +59,6 @@ lyplg_type_store_hex_string(const struct ly_ctx *ctx, const struct lysc_type *ty ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err); LY_CHECK_GOTO(ret, cleanup); - /* length restriction of the string */ - if (type_str->length) { - /* value_len is in bytes, but we need number of characters here */ - ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err); - LY_CHECK_GOTO(ret, cleanup); - } - - /* pattern restrictions */ - ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err); - LY_CHECK_GOTO(ret, cleanup); - /* make a copy, it is needed for canonization */ if ((format != LY_VALUE_CANON) && !(options & LYPLG_TYPE_STORE_DYNAMIC)) { value = strndup(value, value_size); @@ -98,16 +86,7 @@ lyplg_type_store_hex_string(const struct ly_ctx *ctx, const struct lysc_type *ty } if (!(options & LYPLG_TYPE_STORE_ONLY)) { - /* validate length restriction of the string */ - if (type_str->length) { - /* value_size is in bytes, but we need number of characters here */ - ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_size), value, - value_size, err); - LY_CHECK_GOTO(ret, cleanup); - } - - /* validate pattern restrictions */ - ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err); + ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err); LY_CHECK_GOTO(ret, cleanup); } @@ -138,7 +117,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .plugin.id = "ly2 hex-string", .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes, .plugin.store = lyplg_type_store_hex_string, - .plugin.validate = NULL, + .plugin.validate = lyplg_type_validate_string, .plugin.compare = lyplg_type_compare_simple, .plugin.sort = lyplg_type_sort_simple, .plugin.print = lyplg_type_print_simple, @@ -153,7 +132,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .plugin.id = "ly2 hex-string", .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes, .plugin.store = lyplg_type_store_hex_string, - .plugin.validate = NULL, + .plugin.validate = lyplg_type_validate_string, .plugin.compare = lyplg_type_compare_simple, .plugin.sort = lyplg_type_sort_simple, .plugin.print = lyplg_type_print_simple, @@ -168,7 +147,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .plugin.id = "ly2 hex-string", .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes, .plugin.store = lyplg_type_store_hex_string, - .plugin.validate = NULL, + .plugin.validate = lyplg_type_validate_string, .plugin.compare = lyplg_type_compare_simple, .plugin.sort = lyplg_type_sort_simple, .plugin.print = lyplg_type_print_simple, @@ -183,7 +162,7 @@ const struct lyplg_type_record plugins_hex_string[] = { .plugin.id = "ly2 hex-string", .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes, .plugin.store = lyplg_type_store_hex_string, - .plugin.validate = NULL, + .plugin.validate = lyplg_type_validate_string, .plugin.compare = lyplg_type_compare_simple, .plugin.sort = lyplg_type_sort_simple, .plugin.print = lyplg_type_print_simple, diff --git a/src/plugins_types/instanceid_keys.c b/src/plugins_types/instanceid_keys.c index 5d240fcfc..d4d96c103 100644 --- a/src/plugins_types/instanceid_keys.c +++ b/src/plugins_types/instanceid_keys.c @@ -138,7 +138,6 @@ lyplg_type_store_instanceid_keys(const struct ly_ctx *ctx, const struct lysc_typ struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; - struct lysc_type_str *type_str = (struct lysc_type_str *)type; struct lyd_value_instance_identifier_keys *val; uint32_t value_size, *prev_lo, temp_lo = LY_LOSTORE; const struct ly_err_item *eitem; @@ -159,17 +158,6 @@ lyplg_type_store_instanceid_keys(const struct ly_ctx *ctx, const struct lysc_typ ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err); LY_CHECK_GOTO(ret, cleanup); - /* length restriction of the string */ - if (type_str->length) { - /* value_size is in bytes, but we need number of characters here */ - ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_size), value, value_size, err); - LY_CHECK_GOTO(ret, cleanup); - } - - /* pattern restrictions */ - ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_size, err); - LY_CHECK_GOTO(ret, cleanup); - /* parse instance-identifier keys, with optional prefix even though it should be mandatory */ if (value_size && (((char *)value)[0] != '[')) { ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid first character '%c', list key predicates expected.", @@ -221,6 +209,11 @@ lyplg_type_store_instanceid_keys(const struct ly_ctx *ctx, const struct lysc_typ break; } + if (!(options & LYPLG_TYPE_STORE_ONLY)) { + ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err); + LY_CHECK_GOTO(ret, cleanup); + } + cleanup: if (options & LYPLG_TYPE_STORE_DYNAMIC) { free((void *)value); @@ -248,7 +241,7 @@ const struct lyplg_type_record plugins_instanceid_keys[] = { .plugin.id = "ly2 instance-identifier-keys", .plugin.lyb_size = lyplg_type_lyb_size_variable_bytes, .plugin.store = lyplg_type_store_instanceid_keys, - .plugin.validate = NULL, + .plugin.validate = lyplg_type_validate_string, .plugin.compare = lyplg_type_compare_simple, .plugin.sort = lyplg_type_sort_simple, .plugin.print = lyplg_type_print_xpath10, diff --git a/src/plugins_types/integer.c b/src/plugins_types/integer.c index 91afa85e4..9e7ab18a3 100644 --- a/src/plugins_types/integer.c +++ b/src/plugins_types/integer.c @@ -40,9 +40,11 @@ */ static LY_ERR lyplg_type_validate_int(const struct ly_ctx *ctx, const struct lysc_type *type, - const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err); + const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext, + struct lyd_value *storage, struct ly_err_item **err); static LY_ERR lyplg_type_validate_uint(const struct ly_ctx *ctx, const struct lysc_type *type, - const struct lyd_node *ctx_node, const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err); + const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lysc_ext_instance *top_ext, + struct lyd_value *storage, struct ly_err_item **err); static LY_ERR lyplg_type_store_int(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, uint32_t value_size_bits, @@ -51,7 +53,6 @@ lyplg_type_store_int(const struct ly_ctx *ctx, const struct lysc_type *type, con struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; - struct lysc_type_num *type_num = (struct lysc_type_num *)type; uint32_t value_size; int64_t num = 0; int base = 1; @@ -155,7 +156,7 @@ lyplg_type_store_int(const struct ly_ctx *ctx, const struct lysc_type *type, con if (!(options & LYPLG_TYPE_STORE_ONLY)) { /* validate value */ - ret = lyplg_type_validate_int(ctx, type, NULL, NULL, storage, err); + ret = lyplg_type_validate_int(ctx, type, NULL, NULL, NULL, storage, err); LY_CHECK_GOTO(ret, cleanup); } @@ -175,7 +176,8 @@ cleanup: */ static LY_ERR lyplg_type_validate_int(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), - const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err) + const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext), + struct lyd_value *storage, struct ly_err_item **err) { LY_ERR ret; struct lysc_type_num *type_num = (struct lysc_type_num *)type; @@ -357,7 +359,6 @@ lyplg_type_store_uint(const struct ly_ctx *ctx, const struct lysc_type *type, co struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; - struct lysc_type_num *type_num = (struct lysc_type_num *)type; uint32_t value_size; uint64_t num = 0; int base = 0; @@ -441,7 +442,7 @@ lyplg_type_store_uint(const struct ly_ctx *ctx, const struct lysc_type *type, co if (!(options & LYPLG_TYPE_STORE_ONLY)) { /* validate value */ - ret = lyplg_type_validate_uint(ctx, type, NULL, NULL, storage, err); + ret = lyplg_type_validate_uint(ctx, type, NULL, NULL, NULL, storage, err); LY_CHECK_GOTO(ret, cleanup); } @@ -461,7 +462,8 @@ cleanup: */ static LY_ERR lyplg_type_validate_uint(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), - const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err) + const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext), + struct lyd_value *storage, struct ly_err_item **err) { LY_ERR ret; struct lysc_type_num *type_num = (struct lysc_type_num *)type; diff --git a/src/plugins_types/ipv4_address_no_zone.c b/src/plugins_types/ipv4_address_no_zone.c index e5fa0c772..86656afbd 100644 --- a/src/plugins_types/ipv4_address_no_zone.c +++ b/src/plugins_types/ipv4_address_no_zone.c @@ -65,7 +65,6 @@ lyplg_type_store_ipv4_address_no_zone(const struct ly_ctx *ctx, const struct lys struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; - struct lysc_type_str *type_str = (struct lysc_type_str *)type; struct lyd_value_ipv4_address_no_zone *val; uint32_t value_size; @@ -92,17 +91,6 @@ lyplg_type_store_ipv4_address_no_zone(const struct ly_ctx *ctx, const struct lys ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err); LY_CHECK_GOTO(ret, cleanup); - /* length restriction of the string */ - if (type_str->length) { - /* value_len is in bytes, but we need number of characters here */ - ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err); - LY_CHECK_GOTO(ret, cleanup); - } - - /* pattern restrictions */ - ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err); - LY_CHECK_GOTO(ret, cleanup); - /* we always need a dynamic value */ if (!(options & LYPLG_TYPE_STORE_DYNAMIC)) { value = strndup(value, value_size); diff --git a/src/plugins_types/ipv4_prefix.c b/src/plugins_types/ipv4_prefix.c index de91982b0..50ac57194 100644 --- a/src/plugins_types/ipv4_prefix.c +++ b/src/plugins_types/ipv4_prefix.c @@ -76,9 +76,12 @@ ipv4prefix_str2ip(const char *value, uint32_t value_len, struct in_addr *addr, u const char *pref_str; char *mask_str = NULL; - /* it passed the pattern validation */ + /* Parse and check the prefix before masking the address. */ pref_str = ly_strnchr(value, '/', value_len); - ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix); + if (!pref_str || (pref_str + 1 == value + value_len) || + ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix) || (*prefix > 32)) { + return ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid IPv4 prefix \"%.*s\".", (int)value_len, value); + } /* get just the network prefix */ mask_str = strndup(value, pref_str - value); @@ -128,7 +131,6 @@ lyplg_type_store_ipv4_prefix(const struct ly_ctx *ctx, const struct lysc_type *t struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; - struct lysc_type_str *type_str = (struct lysc_type_str *)type; struct lyd_value_ipv4_prefix *val; uint32_t value_size; @@ -165,14 +167,6 @@ lyplg_type_store_ipv4_prefix(const struct ly_ctx *ctx, const struct lysc_type *t ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err); LY_CHECK_GOTO(ret, cleanup); - /* pattern restrictions */ - ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err); - LY_CHECK_GOTO(ret, cleanup); - - /* pattern restrictions */ - ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err); - LY_CHECK_GOTO(ret, cleanup); - /* get the mask in network-byte order */ ret = ipv4prefix_str2ip(value, value_size, &val->addr, &val->prefix, err); LY_CHECK_GOTO(ret, cleanup); diff --git a/src/plugins_types/ipv6_address_no_zone.c b/src/plugins_types/ipv6_address_no_zone.c index 0a483a883..45ca9bb5a 100644 --- a/src/plugins_types/ipv6_address_no_zone.c +++ b/src/plugins_types/ipv6_address_no_zone.c @@ -104,7 +104,6 @@ lyplg_type_store_ipv6_address_no_zone(const struct ly_ctx *ctx, const struct lys struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; - struct lysc_type_str *type_str = (struct lysc_type_str *)type; struct lyd_value_ipv6_address_no_zone *val; uint32_t value_size; diff --git a/src/plugins_types/ipv6_prefix.c b/src/plugins_types/ipv6_prefix.c index c3f67affc..93f86610d 100644 --- a/src/plugins_types/ipv6_prefix.c +++ b/src/plugins_types/ipv6_prefix.c @@ -68,9 +68,12 @@ ipv6prefix_str2ip(const char *value, uint32_t value_len, struct in6_addr *addr, const char *pref_str; char *mask_str = NULL; - /* it passed the pattern validation */ + /* Parse and check the prefix before masking the address. */ pref_str = ly_strnchr(value, '/', value_len); - ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix); + if (!pref_str || (pref_str + 1 == value + value_len) || + ly_strntou8(pref_str + 1, value_len - (pref_str + 1 - value), prefix) || (*prefix > 128)) { + return ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "Invalid IPv6 prefix \"%.*s\".", (int)value_len, value); + } /* get just the network prefix */ mask_str = strndup(value, pref_str - value); @@ -130,7 +133,6 @@ lyplg_type_store_ipv6_prefix(const struct ly_ctx *ctx, const struct lysc_type *t struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; - struct lysc_type_str *type_str = (struct lysc_type_str *)type; struct lyd_value_ipv6_prefix *val; uint32_t value_size; diff --git a/src/plugins_types/string.c b/src/plugins_types/string.c index 90c64b98b..99b12cf10 100644 --- a/src/plugins_types/string.c +++ b/src/plugins_types/string.c @@ -34,8 +34,6 @@ * | variable, full bytes | yes | `char *` | string itself | */ -static LY_ERR lyplg_type_validate_string(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err); - /** * @brief Check string value for invalid characters. * @@ -66,7 +64,6 @@ lyplg_type_store_string(const struct ly_ctx *ctx, const struct lysc_type *type, struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err) { LY_ERR ret = LY_SUCCESS; - struct lysc_type_str *type_str = (struct lysc_type_str *)type; uint32_t value_size; /* init storage */ @@ -102,7 +99,7 @@ lyplg_type_store_string(const struct ly_ctx *ctx, const struct lysc_type *type, if (!(options & LYPLG_TYPE_STORE_ONLY)) { /* validate value */ - ret = lyplg_type_validate_string(ctx, type, NULL, NULL, storage, err); + ret = lyplg_type_validate_string(ctx, type, NULL, NULL, NULL, storage, err); LY_CHECK_GOTO(ret, cleanup); } @@ -120,9 +117,10 @@ cleanup: /** * @brief Implementation of ::lyplg_type_validate_clb for the string type. */ -static LY_ERR +LY_ERR lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), - const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err) + const struct lyd_node *UNUSED(tree), const struct lysc_ext_instance *UNUSED(top_ext), + struct lyd_value *storage, struct ly_err_item **err) { LY_ERR ret; struct lysc_type_str *type_str = (struct lysc_type_str *)type; @@ -142,7 +140,7 @@ lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *typ } /* pattern restrictions */ - ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err); + ret = lyplg_type_validate_patterns(ctx, type_str->patterns, value, value_len, err); LY_CHECK_RET(ret); return LY_SUCCESS; diff --git a/src/plugins_types/xpath1.0.c b/src/plugins_types/xpath1.0.c index 5544148cc..a78eef1a1 100644 --- a/src/plugins_types/xpath1.0.c +++ b/src/plugins_types/xpath1.0.c @@ -250,7 +250,6 @@ lyplg_type_store_xpath10(const struct ly_ctx *ctx, const struct lysc_type *type, { LY_ERR ret = LY_SUCCESS; uint32_t value_size; - struct lysc_type_str *type_str = (struct lysc_type_str *)type; struct lyd_value_xpath10 *val; char *canon; @@ -269,17 +268,6 @@ lyplg_type_store_xpath10(const struct ly_ctx *ctx, const struct lysc_type *type, ret = lyplg_type_check_hints(hints, value, value_size, type->basetype, NULL, err); LY_CHECK_GOTO(ret, cleanup); - /* length restriction of the string */ - if (type_str->length) { - /* value_len is in bytes, but we need number of characters here */ - ret = lyplg_type_validate_range(LY_TYPE_STRING, type_str->length, ly_utf8len(value, value_len), value, value_len, err); - LY_CHECK_GOTO(ret, cleanup); - } - - /* pattern restrictions */ - ret = lyplg_type_validate_patterns(type_str->patterns, value, value_len, err); - LY_CHECK_GOTO(ret, cleanup); - /* parse */ ret = lyxp_expr_parse(ctx, value_size ? value : "", value_size, 1, &val->exp); LY_CHECK_GOTO(ret, cleanup);
model_resultsuccess
passedtrue
repoCESNET/libyang
scaffoldmini-swe-agent@2.4.6
subsettest