diff options
author | itojun <> | 2002-06-26 06:01:16 +0000 |
---|---|---|
committer | itojun <> | 2002-06-26 06:01:16 +0000 |
commit | f1f381f26db98078dfc10572dbe1aa273fc16d94 (patch) | |
tree | 269c86f8c2ae89cb848e0115f62fafa05558b084 /src/lib/libc/net/getaddrinfo.c | |
parent | 2de6ddb6a22feedbcbc44271ca3841ddc526981b (diff) | |
download | openbsd-f1f381f26db98078dfc10572dbe1aa273fc16d94.tar.gz openbsd-f1f381f26db98078dfc10572dbe1aa273fc16d94.tar.bz2 openbsd-f1f381f26db98078dfc10572dbe1aa273fc16d94.zip |
correct bad practice in the code - it uses two changing variables
to manage buffer (buf and buflen). we eliminate buflen and use
fixed point (ep) as the ending pointer.
this fix is NOT critical.
Diffstat (limited to 'src/lib/libc/net/getaddrinfo.c')
-rw-r--r-- | src/lib/libc/net/getaddrinfo.c | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c index d16900b4a0..3f4d916486 100644 --- a/src/lib/libc/net/getaddrinfo.c +++ b/src/lib/libc/net/getaddrinfo.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getaddrinfo.c,v 1.33 2002/02/17 19:42:23 millert Exp $ */ | 1 | /* $OpenBSD: getaddrinfo.c,v 1.34 2002/06/26 06:01:16 itojun Exp $ */ |
2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ | 2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -1031,8 +1031,8 @@ getanswer(answer, anslen, qname, qtype, pai) | |||
1031 | const u_char *cp; | 1031 | const u_char *cp; |
1032 | int n; | 1032 | int n; |
1033 | const u_char *eom; | 1033 | const u_char *eom; |
1034 | char *bp; | 1034 | char *bp, *ep; |
1035 | int type, class, buflen, ancount, qdcount; | 1035 | int type, class, ancount, qdcount; |
1036 | int haveanswer, had_error; | 1036 | int haveanswer, had_error; |
1037 | char tbuf[MAXDNAME]; | 1037 | char tbuf[MAXDNAME]; |
1038 | int (*name_ok)(const char *); | 1038 | int (*name_ok)(const char *); |
@@ -1059,13 +1059,13 @@ getanswer(answer, anslen, qname, qtype, pai) | |||
1059 | ancount = ntohs(hp->ancount); | 1059 | ancount = ntohs(hp->ancount); |
1060 | qdcount = ntohs(hp->qdcount); | 1060 | qdcount = ntohs(hp->qdcount); |
1061 | bp = hostbuf; | 1061 | bp = hostbuf; |
1062 | buflen = sizeof hostbuf; | 1062 | ep = hostbuf + sizeof hostbuf; |
1063 | cp = answer->buf + HFIXEDSZ; | 1063 | cp = answer->buf + HFIXEDSZ; |
1064 | if (qdcount != 1) { | 1064 | if (qdcount != 1) { |
1065 | h_errno = NO_RECOVERY; | 1065 | h_errno = NO_RECOVERY; |
1066 | return (NULL); | 1066 | return (NULL); |
1067 | } | 1067 | } |
1068 | n = dn_expand(answer->buf, eom, cp, bp, buflen); | 1068 | n = dn_expand(answer->buf, eom, cp, bp, ep - bp); |
1069 | if ((n < 0) || !(*name_ok)(bp)) { | 1069 | if ((n < 0) || !(*name_ok)(bp)) { |
1070 | h_errno = NO_RECOVERY; | 1070 | h_errno = NO_RECOVERY; |
1071 | return (NULL); | 1071 | return (NULL); |
@@ -1083,14 +1083,13 @@ getanswer(answer, anslen, qname, qtype, pai) | |||
1083 | } | 1083 | } |
1084 | canonname = bp; | 1084 | canonname = bp; |
1085 | bp += n; | 1085 | bp += n; |
1086 | buflen -= n; | ||
1087 | /* The qname can be abbreviated, but h_name is now absolute. */ | 1086 | /* The qname can be abbreviated, but h_name is now absolute. */ |
1088 | qname = canonname; | 1087 | qname = canonname; |
1089 | } | 1088 | } |
1090 | haveanswer = 0; | 1089 | haveanswer = 0; |
1091 | had_error = 0; | 1090 | had_error = 0; |
1092 | while (ancount-- > 0 && cp < eom && !had_error) { | 1091 | while (ancount-- > 0 && cp < eom && !had_error) { |
1093 | n = dn_expand(answer->buf, eom, cp, bp, buflen); | 1092 | n = dn_expand(answer->buf, eom, cp, bp, ep - bp); |
1094 | if ((n < 0) || !(*name_ok)(bp)) { | 1093 | if ((n < 0) || !(*name_ok)(bp)) { |
1095 | had_error++; | 1094 | had_error++; |
1096 | continue; | 1095 | continue; |
@@ -1117,14 +1116,13 @@ getanswer(answer, anslen, qname, qtype, pai) | |||
1117 | cp += n; | 1116 | cp += n; |
1118 | /* Get canonical name. */ | 1117 | /* Get canonical name. */ |
1119 | n = strlen(tbuf) + 1; /* for the \0 */ | 1118 | n = strlen(tbuf) + 1; /* for the \0 */ |
1120 | if (n > buflen || n >= MAXHOSTNAMELEN) { | 1119 | if (n > ep - bp || n >= MAXHOSTNAMELEN) { |
1121 | had_error++; | 1120 | had_error++; |
1122 | continue; | 1121 | continue; |
1123 | } | 1122 | } |
1124 | strcpy(bp, tbuf); | 1123 | strcpy(bp, tbuf); |
1125 | canonname = bp; | 1124 | canonname = bp; |
1126 | bp += n; | 1125 | bp += n; |
1127 | buflen -= n; | ||
1128 | continue; | 1126 | continue; |
1129 | } | 1127 | } |
1130 | if (qtype == T_ANY) { | 1128 | if (qtype == T_ANY) { |
@@ -1164,7 +1162,6 @@ getanswer(answer, anslen, qname, qtype, pai) | |||
1164 | canonname = bp; | 1162 | canonname = bp; |
1165 | nn = strlen(bp) + 1; /* for the \0 */ | 1163 | nn = strlen(bp) + 1; /* for the \0 */ |
1166 | bp += nn; | 1164 | bp += nn; |
1167 | buflen -= nn; | ||
1168 | } | 1165 | } |
1169 | 1166 | ||
1170 | /* don't overwrite pai */ | 1167 | /* don't overwrite pai */ |