siva-msft / libgit2

Other
0 stars 1 forks source link

Potential issue in src/refdb_fs.c: Return Value Not Checked from Function Call #54

Open monocle-ai opened 4 years ago

monocle-ai commented 4 years ago

In this codebase, you often check the return value of the implicated function when calling it, but in this instance, it appears that you didn’t. Using a consistent return value checking and/or error handling approach can improve code robustness and readability.

2 instances of this defect were found in the following locations:


Instance 1 File : src/refdb_fs.c Enclosing Function : serialize_reflog_entry Function : git_oid_tostr https://github.com/siva-msft/libgit2/blob/1e987525b3bd86fc29e7ff67d973861efd22faf7/src/refdb_fs.c#L1770 Code extract:

    char raw_old[GIT_OID_HEXSZ+1];
    char raw_new[GIT_OID_HEXSZ+1];

    git_oid_tostr(raw_old, GIT_OID_HEXSZ+1, oid_old); <------ HERE
    git_oid_tostr(raw_new, GIT_OID_HEXSZ+1, oid_new);

How can I fix it? Correct reference usage found in src/diff_generate.c at line 1649. https://github.com/siva-msft/libgit2/blob/1e987525b3bd86fc29e7ff67d973861efd22faf7/src/diff_generate.c#L1649 Code extract:


        error = -1;
        git_error_set(GIT_ERROR_INVALID, "commit %s is a merge commit",
            git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit))); <------ HERE
        goto on_error;
    }

Instance 2 File : src/refdb_fs.c Enclosing Function : serialize_reflog_entry Function : git_oid_tostr https://github.com/siva-msft/libgit2/blob/1e987525b3bd86fc29e7ff67d973861efd22faf7/src/refdb_fs.c#L1771 Code extract:

    char raw_new[GIT_OID_HEXSZ+1];

    git_oid_tostr(raw_old, GIT_OID_HEXSZ+1, oid_old);
    git_oid_tostr(raw_new, GIT_OID_HEXSZ+1, oid_new); <------ HERE

    git_buf_clear(buf);

How can I fix it? Correct reference usage found in src/diff_generate.c at line 1649. https://github.com/siva-msft/libgit2/blob/1e987525b3bd86fc29e7ff67d973861efd22faf7/src/diff_generate.c#L1649 Code extract:


        error = -1;
        git_error_set(GIT_ERROR_INVALID, "commit %s is a merge commit",
            git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit))); <------ HERE
        goto on_error;
    }