weixin_39588542
weixin_39588542
2020-12-08 19:23

libyang2: schema tree BUGFIX lys_compile_unres_xpath must null dereference

Hello,

this is similar to #1200. The file causing the crash is below:


module d{
    namespace "";
    prefix d;
    leaf f {
        type string;
        must "0e";
        default "";
    }
}

To reproduce this, the same example from #1200 can be used:


#include <stdio.h>
#include <libyang>

int main(int argc, char **argv) {
    struct ly_ctx *ctx = NULL;
    FILE *f = NULL;
    size_t len = 0;
    int err = 0;
    char *data = NULL;

    if (argc != 2) {
        printf("invalid number of arguments\n");
        return -1;
    }

    ly_log_options(0);
    err = ly_ctx_new(NULL, 0, &ctx);
    if (err != LY_SUCCESS) {
        printf("context fail\n");
        return -1;
    }

    f = fopen(argv[1], "r");
    if (f == NULL) {
        printf("fopen fail\n");
        return -1;
    }

    fseek(f, 0, SEEK_END);
    len = ftell(f);
    fseek(f, 0, SEEK_SET);

    data = malloc(len + 1);
    if (data == NULL) {
        printf("malloc fail\n");
        fclose(f);
        return -1;
    }

    fread(data, len, 1, f);
    data[len] = 0;

    lys_parse_mem(ctx, data, LYS_IN_YANG, NULL);
    fclose(f);
    free(data);

    return 0;
}
</libyang></stdio.h>

The issue also only appears when libyang logging is turned off.

Regards, Juraj

该提问来源于开源项目:CESNET/libyang

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39945679 weixin_39945679 4月前

    Codecov Report

    Merging #1202 into libyang2 will decrease coverage by 0.01%. The diff coverage is n/a.

    diff
    @@             Coverage Diff              @@
    ##           libyang2    #1202      +/-   ##
    ============================================
    - Coverage     74.41%   74.40%   -0.01%     
    ============================================
      Files            39       39              
      Lines         25225    25227       +2     
    ============================================
      Hits          18770    18770              
    - Misses         6455     6457       +2     
    
    点赞 评论 复制链接分享
  • weixin_39826080 weixin_39826080 4月前

    From my perspective, it is kind of duplication of #1200 - again, we are using error information stored in context, but in case you switch off the logging, that information is not present.

    点赞 评论 复制链接分享
  • weixin_39857792 weixin_39857792 4月前

    Should also be fixed now.

    点赞 评论 复制链接分享
  • weixin_39588542 weixin_39588542 4月前

    1205 fixed this as well, so I'm closing the issue.

    点赞 评论 复制链接分享

为你推荐