FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.15] gh-159739: Account for NUL terminators in fallback getnameinfo (GH-159991) by miss-islington · Pull Request #160091 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix off-by-one output buffer checks in the fallback implementation of
``getnameinfo()``.
10 changes: 5 additions & 5 deletions Modules/getnameinfo.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen,
/* what we should do? */
} else if (flags & NI_NUMERICSERV) {
sprintf(numserv, "%d", ntohs(port));
if (strlen(numserv) > servlen)
if (strlen(numserv) >= servlen)
return ENI_MEMORY;
strcpy(serv, numserv);
} else {
sp = getservbyport(port, (flags & NI_DGRAM) ? "udp" : "tcp");
if (sp) {
if (strlen(sp->s_name) > servlen)
if (strlen(sp->s_name) >= servlen)
return ENI_MEMORY;
strcpy(serv, sp->s_name);
} else
Expand Down Expand Up @@ -166,7 +166,7 @@ getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen,
if (inet_ntop(gni_afd->a_af, addr, numaddr, sizeof(numaddr))
== NULL)
return ENI_SYSTEM;
if (strlen(numaddr) > hostlen)
if (strlen(numaddr) >= hostlen)
return ENI_MEMORY;
strcpy(host, numaddr);
} else {
Expand All @@ -181,7 +181,7 @@ getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen,
p = strchr(hp->h_name, '.');
if (p) *p = '\0';
}
if (strlen(hp->h_name) > hostlen) {
if (strlen(hp->h_name) >= hostlen) {
#ifdef ENABLE_IPV6
freehostent(hp);
#endif
Expand All @@ -197,7 +197,7 @@ getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen,
if (inet_ntop(gni_afd->a_af, addr, numaddr, sizeof(numaddr))
== NULL)
return ENI_NOHOSTNAME;
if (strlen(numaddr) > hostlen)
if (strlen(numaddr) >= hostlen)
return ENI_MEMORY;
strcpy(host, numaddr);
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL