Skip to content

in BUGFIX ly_in_filepath() error value for a handler of another type - #2643

Open
GeekQAQ wants to merge 1 commit into
CESNET:develfrom
GeekQAQ:in-filepath-argret
Open

GeekQAQ wants to merge 1 commit into
CESNET:develfrom
GeekQAQ:in-filepath-argret

Conversation

@GeekQAQ

@GeekQAQ GeekQAQ commented Nov 19, 2026

Copy link
Copy Markdown

ly_in_filepath() documents "NULL if changing filepath succeeds and ((void *)-1) otherwise". When the handler is not an LY_IN_FILEPATH one (or is NULL), the argument check logs "Invalid argument" but returns NULL for a change and (void *)-1 for a query, the opposite of the documented values. The caller is told that the change succeeded and the handler keeps reading its previous data.

#include <stdio.h>

#include <libyang/libyang.h>

int
main(void)
{
    struct ly_in *in;
    const char *ret;
    char buf[4] = {0};

    ly_in_new_memory("old data", &in);

    /* the handler is not of the LY_IN_FILEPATH type, the call is refused */
    ret = ly_in_filepath(in, "new.json", 0);
    printf("ly_in_filepath() returned %s\n", !ret ? "NULL (success)" : (ret == (void *)-1) ? "(void *)-1" : ret);
    ly_in_read(in, buf, 3);
    printf("read \"%s\"\n", buf);

    ly_in_free(in, 0);
    return 0;
}

On devel f45939c:

libyang[0]: Invalid argument in->type == LY_IN_FILEPATH (ly_in_filepath()).
ly_in_filepath() returned NULL (success)
read "old"

The same happens for handlers created by ly_in_new_fd() and ly_in_new_file(), and with a NULL handler.

The documentation does not say which handler types ly_in_filepath() accepts; the function treats other types as an invalid argument, and for that the documented value is (void *)-1.

Fix: return (void *)-1 from the argument check in both cases. A query on such a handler already returned it, so only the change case differs. The new cases in test_input_filepath fail on the current tree and pass with the fix.

Tested on devel f45939c with clang 21, -fsanitize=address,undefined, ENABLE_TESTS=ON: ctest passes (70 tests).

When the handler was NULL or not of the LY_IN_FILEPATH type, the
argument check returned NULL, the documented success value, for a
change of the file path. Return ((void *)-1) for both a change and
a query.
Copilot AI balanced review requested due to automatic review settings November 19, 2026 21:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants