Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Few p_getaddrinfo fixes #3567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 29, 2016
Merged

Conversation

sba1
Copy link
Contributor

@sba1 sba1 commented Dec 31, 2015

These are some (hopefully correct) fixes for the p_getaddrinfo() function.

If you prefer to use GITERR_CHECK_ALLOC() in commit ea5942b I can also do it of course.

@@ -62,8 +62,11 @@ int p_getaddrinfo(
ai = ainfo;

for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) {
ai->ai_next = malloc(sizeof(struct addrinfo));
memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo));
if (!(ai->ai_next = malloc(sizeof(struct addrinfo)))) {
Copy link
Member

Choose a reason for hiding this comment

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

We should be using git__malloc() here, or even git__calloc(). And yes, we should just bail out with the macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Am 2015-12-31 16:19, schrieb Carlos Martín Nieto:

In src/posix.c [1]:

@@ -62,8 +62,11 @@ int p_getaddrinfo(
ai = ainfo;

 for (p = 1; ainfo->ai_hostent->h_addr_list[p] != NULL; p++) {
  •    ai->ai_next = malloc(sizeof(struct addrinfo));
    
  •    memcpy(&ai->ai_next, ainfo, sizeof(struct addrinfo));
    
  •    if (!(ai->ai_next = malloc(sizeof(struct addrinfo)))) {
    

We should be using git__malloc() here, or even git__calloc(). And yes,
we should just bail out with the macro.

Note however that this is a replacement function for getaddrinfo() that
also doesn't follow libgit2 semantics. For instance, GITERR_CHECK_ALLOC
will not clean up properly while the standard getaddrinfo() is supposed
to cleanup properly in a failure case. So should this really being used?
In posix.c there is quite a mixture of styles so it is not clear what
style should be really used. But if you say git__malloc() and
GITERR_CHECK_ALLOC then I will adjust my changes.

Copy link
Member

Choose a reason for hiding this comment

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

It's not 100% expected that the p_* functions that we write should set library error codes. These are often used as fallbacks when an actual posix function is not available. And - of course - the actual posix functions (like the system's getaddrinfo) will never set the library error codes.

Therefore p_getaddrinfo doesn't need to set the library error code. Instead, it needs to set something that p_gai_strerror can cope with (which is our reimplementation of gai_strerror. Indeed that does so - -1 is treated as an OOM scenario.

As a result, I think this change is correct.

ethomson pushed a commit that referenced this pull request Feb 29, 2016
@ethomson ethomson merged commit dbee683 into libgit2:master Feb 29, 2016
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.

3 participants