diff options
| author | deraadt <> | 2017-01-24 10:33:16 +0000 |
|---|---|---|
| committer | deraadt <> | 2017-01-24 10:33:16 +0000 |
| commit | f5db1b892e56a62e47a445aac13bb563d788a618 (patch) | |
| tree | c626a7fbde1ee727db1df12ea9ecfc397f023f92 | |
| parent | b857b8c016afaa1a8615fad00878c896da3c0e53 (diff) | |
| download | openbsd-f5db1b892e56a62e47a445aac13bb563d788a618.tar.gz openbsd-f5db1b892e56a62e47a445aac13bb563d788a618.tar.bz2 openbsd-f5db1b892e56a62e47a445aac13bb563d788a618.zip | |
Yes the "if (const == val" idiom provides some safety, but it grates on
us too much.
ok beck jsing
Diffstat (limited to '')
| -rw-r--r-- | src/usr.sbin/ocspcheck/http.c | 116 |
1 files changed, 58 insertions, 58 deletions
diff --git a/src/usr.sbin/ocspcheck/http.c b/src/usr.sbin/ocspcheck/http.c index 7964cc89f7..c5577791d9 100644 --- a/src/usr.sbin/ocspcheck/http.c +++ b/src/usr.sbin/ocspcheck/http.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $Id: http.c,v 1.3 2017/01/24 10:02:11 beck Exp $ */ | 1 | /* $Id: http.c,v 1.4 2017/01/24 10:33:16 deraadt Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv> | 3 | * Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv> |
| 4 | * | 4 | * |
| @@ -95,7 +95,7 @@ dotlsread(char *buf, size_t sz, const struct http *http) | |||
| 95 | 95 | ||
| 96 | do { | 96 | do { |
| 97 | rc = tls_read(http->ctx, buf, sz); | 97 | rc = tls_read(http->ctx, buf, sz); |
| 98 | } while (TLS_WANT_POLLIN == rc || TLS_WANT_POLLOUT == rc); | 98 | } while (rc == TLS_WANT_POLLIN || rc == TLS_WANT_POLLOUT); |
| 99 | 99 | ||
| 100 | if (rc < 0) | 100 | if (rc < 0) |
| 101 | warnx("%s: tls_read: %s", http->src.ip, | 101 | warnx("%s: tls_read: %s", http->src.ip, |
| @@ -110,7 +110,7 @@ dotlswrite(const void *buf, size_t sz, const struct http *http) | |||
| 110 | 110 | ||
| 111 | do { | 111 | do { |
| 112 | rc = tls_write(http->ctx, buf, sz); | 112 | rc = tls_write(http->ctx, buf, sz); |
| 113 | } while (TLS_WANT_POLLIN == rc || TLS_WANT_POLLOUT == rc); | 113 | } while (rc == TLS_WANT_POLLIN || rc == TLS_WANT_POLLOUT); |
| 114 | 114 | ||
| 115 | if (rc < 0) | 115 | if (rc < 0) |
| 116 | warnx("%s: tls_write: %s", http->src.ip, | 116 | warnx("%s: tls_write: %s", http->src.ip, |
| @@ -121,21 +121,21 @@ dotlswrite(const void *buf, size_t sz, const struct http *http) | |||
| 121 | int | 121 | int |
| 122 | http_init() | 122 | http_init() |
| 123 | { | 123 | { |
| 124 | if (NULL != tlscfg) | 124 | if (tlscfg != NULL) |
| 125 | return (0); | 125 | return (0); |
| 126 | 126 | ||
| 127 | if (-1 == tls_init()) { | 127 | if (tls_init() == -1) { |
| 128 | warn("tls_init"); | 128 | warn("tls_init"); |
| 129 | goto err; | 129 | goto err; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | tlscfg = tls_config_new(); | 132 | tlscfg = tls_config_new(); |
| 133 | if (NULL == tlscfg) { | 133 | if (tlscfg == NULL) { |
| 134 | warn("tls_config_new"); | 134 | warn("tls_config_new"); |
| 135 | goto err; | 135 | goto err; |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | if (-1 == tls_config_set_ca_file(tlscfg, DEFAULT_CA_FILE)) { | 138 | if (tls_config_set_ca_file(tlscfg, DEFAULT_CA_FILE) == -1) { |
| 139 | warn("tls_config_set_ca_file: %s", tls_config_error(tlscfg)); | 139 | warn("tls_config_set_ca_file: %s", tls_config_error(tlscfg)); |
| 140 | goto err; | 140 | goto err; |
| 141 | } | 141 | } |
| @@ -158,7 +158,7 @@ http_read(char *buf, size_t sz, const struct http *http) | |||
| 158 | do { | 158 | do { |
| 159 | if ((ssz = http->reader(buf, sz, http)) < 0) | 159 | if ((ssz = http->reader(buf, sz, http)) < 0) |
| 160 | return (-1); | 160 | return (-1); |
| 161 | if (0 == ssz) | 161 | if (ssz == 0) |
| 162 | break; | 162 | break; |
| 163 | xfer += ssz; | 163 | xfer += ssz; |
| 164 | sz -= ssz; | 164 | sz -= ssz; |
| @@ -188,11 +188,11 @@ http_disconnect(struct http *http) | |||
| 188 | { | 188 | { |
| 189 | int rc; | 189 | int rc; |
| 190 | 190 | ||
| 191 | if (NULL != http->ctx) { | 191 | if (http->ctx != NULL) { |
| 192 | /* TLS connection. */ | 192 | /* TLS connection. */ |
| 193 | do { | 193 | do { |
| 194 | rc = tls_close(http->ctx); | 194 | rc = tls_close(http->ctx); |
| 195 | } while (TLS_WANT_POLLIN == rc || TLS_WANT_POLLOUT == rc); | 195 | } while (rc == TLS_WANT_POLLIN || rc == TLS_WANT_POLLOUT); |
| 196 | 196 | ||
| 197 | if (rc < 0) | 197 | if (rc < 0) |
| 198 | warnx("%s: tls_close: %s", http->src.ip, | 198 | warnx("%s: tls_close: %s", http->src.ip, |
| @@ -200,8 +200,8 @@ http_disconnect(struct http *http) | |||
| 200 | 200 | ||
| 201 | tls_free(http->ctx); | 201 | tls_free(http->ctx); |
| 202 | } | 202 | } |
| 203 | if (-1 != http->fd) { | 203 | if (http->fd != -1) { |
| 204 | if (-1 == close(http->fd)) | 204 | if (close(http->fd) == -1) |
| 205 | warn("%s: close", http->src.ip); | 205 | warn("%s: close", http->src.ip); |
| 206 | } | 206 | } |
| 207 | 207 | ||
| @@ -213,7 +213,7 @@ void | |||
| 213 | http_free(struct http *http) | 213 | http_free(struct http *http) |
| 214 | { | 214 | { |
| 215 | 215 | ||
| 216 | if (NULL == http) | 216 | if (http == NULL) |
| 217 | return; | 217 | return; |
| 218 | http_disconnect(http); | 218 | http_disconnect(http); |
| 219 | free(http->host); | 219 | free(http->host); |
| @@ -242,14 +242,14 @@ again: | |||
| 242 | 242 | ||
| 243 | memset(&ss, 0, sizeof(struct sockaddr_storage)); | 243 | memset(&ss, 0, sizeof(struct sockaddr_storage)); |
| 244 | 244 | ||
| 245 | if (4 == addrs[cur].family) { | 245 | if (addrs[cur].family == 4) { |
| 246 | family = PF_INET; | 246 | family = PF_INET; |
| 247 | ((struct sockaddr_in *)&ss)->sin_family = AF_INET; | 247 | ((struct sockaddr_in *)&ss)->sin_family = AF_INET; |
| 248 | ((struct sockaddr_in *)&ss)->sin_port = htons(port); | 248 | ((struct sockaddr_in *)&ss)->sin_port = htons(port); |
| 249 | c = inet_pton(AF_INET, addrs[cur].ip, | 249 | c = inet_pton(AF_INET, addrs[cur].ip, |
| 250 | &((struct sockaddr_in *)&ss)->sin_addr); | 250 | &((struct sockaddr_in *)&ss)->sin_addr); |
| 251 | len = sizeof(struct sockaddr_in); | 251 | len = sizeof(struct sockaddr_in); |
| 252 | } else if (6 == addrs[cur].family) { | 252 | } else if (addrs[cur].family == 6) { |
| 253 | family = PF_INET6; | 253 | family = PF_INET6; |
| 254 | ((struct sockaddr_in6 *)&ss)->sin6_family = AF_INET6; | 254 | ((struct sockaddr_in6 *)&ss)->sin6_family = AF_INET6; |
| 255 | ((struct sockaddr_in6 *)&ss)->sin6_port = htons(port); | 255 | ((struct sockaddr_in6 *)&ss)->sin6_port = htons(port); |
| @@ -264,7 +264,7 @@ again: | |||
| 264 | if (c < 0) { | 264 | if (c < 0) { |
| 265 | warn("%s: inet_ntop", addrs[cur].ip); | 265 | warn("%s: inet_ntop", addrs[cur].ip); |
| 266 | goto again; | 266 | goto again; |
| 267 | } else if (0 == c) { | 267 | } else if (c == 0) { |
| 268 | warnx("%s: inet_ntop", addrs[cur].ip); | 268 | warnx("%s: inet_ntop", addrs[cur].ip); |
| 269 | goto again; | 269 | goto again; |
| 270 | } | 270 | } |
| @@ -272,10 +272,10 @@ again: | |||
| 272 | /* Create socket and connect. */ | 272 | /* Create socket and connect. */ |
| 273 | 273 | ||
| 274 | fd = socket(family, SOCK_STREAM, 0); | 274 | fd = socket(family, SOCK_STREAM, 0); |
| 275 | if (-1 == fd) { | 275 | if (fd == -1) { |
| 276 | warn("%s: socket", addrs[cur].ip); | 276 | warn("%s: socket", addrs[cur].ip); |
| 277 | goto again; | 277 | goto again; |
| 278 | } else if (-1 == connect(fd, (struct sockaddr *)&ss, len)) { | 278 | } else if (connect(fd, (struct sockaddr *)&ss, len) == -1) { |
| 279 | warn("%s: connect", addrs[cur].ip); | 279 | warn("%s: connect", addrs[cur].ip); |
| 280 | close(fd); | 280 | close(fd); |
| 281 | goto again; | 281 | goto again; |
| @@ -284,7 +284,7 @@ again: | |||
| 284 | /* Allocate the communicator. */ | 284 | /* Allocate the communicator. */ |
| 285 | 285 | ||
| 286 | http = calloc(1, sizeof(struct http)); | 286 | http = calloc(1, sizeof(struct http)); |
| 287 | if (NULL == http) { | 287 | if (http == NULL) { |
| 288 | warn("calloc"); | 288 | warn("calloc"); |
| 289 | close(fd); | 289 | close(fd); |
| 290 | return (NULL); | 290 | return (NULL); |
| @@ -295,14 +295,14 @@ again: | |||
| 295 | http->src.ip = strdup(addrs[cur].ip); | 295 | http->src.ip = strdup(addrs[cur].ip); |
| 296 | http->host = strdup(host); | 296 | http->host = strdup(host); |
| 297 | http->path = strdup(path); | 297 | http->path = strdup(path); |
| 298 | if (NULL == http->src.ip || NULL == http->host || NULL == http->path) { | 298 | if (http->src.ip == NULL || http->host == NULL || http->path == NULL) { |
| 299 | warn("strdup"); | 299 | warn("strdup"); |
| 300 | goto err; | 300 | goto err; |
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | /* If necessary, do our TLS setup. */ | 303 | /* If necessary, do our TLS setup. */ |
| 304 | 304 | ||
| 305 | if (443 != port) { | 305 | if (port != 443) { |
| 306 | http->writer = dosyswrite; | 306 | http->writer = dosyswrite; |
| 307 | http->reader = dosysread; | 307 | http->reader = dosysread; |
| 308 | return (http); | 308 | return (http); |
| @@ -311,16 +311,16 @@ again: | |||
| 311 | http->writer = dotlswrite; | 311 | http->writer = dotlswrite; |
| 312 | http->reader = dotlsread; | 312 | http->reader = dotlsread; |
| 313 | 313 | ||
| 314 | if (NULL == (http->ctx = tls_client())) { | 314 | if ((http->ctx = tls_client()) == NULL) { |
| 315 | warn("tls_client"); | 315 | warn("tls_client"); |
| 316 | goto err; | 316 | goto err; |
| 317 | } else if (-1 == tls_configure(http->ctx, tlscfg)) { | 317 | } else if (tls_configure(http->ctx, tlscfg) == -1) { |
| 318 | warnx("%s: tls_configure: %s", | 318 | warnx("%s: tls_configure: %s", |
| 319 | http->src.ip, tls_error(http->ctx)); | 319 | http->src.ip, tls_error(http->ctx)); |
| 320 | goto err; | 320 | goto err; |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | if (0 != tls_connect_socket(http->ctx, http->fd, http->host)) { | 323 | if (tls_connect_socket(http->ctx, http->fd, http->host) != 0) { |
| 324 | warnx("%s: tls_connect_socket: %s, %s", http->src.ip, | 324 | warnx("%s: tls_connect_socket: %s, %s", http->src.ip, |
| 325 | http->host, tls_error(http->ctx)); | 325 | http->host, tls_error(http->ctx)); |
| 326 | goto err; | 326 | goto err; |
| @@ -339,7 +339,7 @@ http_open(const struct http *http, const void *p, size_t psz) | |||
| 339 | int c; | 339 | int c; |
| 340 | struct httpxfer *trans; | 340 | struct httpxfer *trans; |
| 341 | 341 | ||
| 342 | if (NULL == p) { | 342 | if (p == NULL) { |
| 343 | c = asprintf(&req, | 343 | c = asprintf(&req, |
| 344 | "GET %s HTTP/1.0\r\n" | 344 | "GET %s HTTP/1.0\r\n" |
| 345 | "Host: %s\r\n" | 345 | "Host: %s\r\n" |
| @@ -355,13 +355,13 @@ http_open(const struct http *http, const void *p, size_t psz) | |||
| 355 | "\r\n", | 355 | "\r\n", |
| 356 | http->path, http->host, psz); | 356 | http->path, http->host, psz); |
| 357 | } | 357 | } |
| 358 | if (-1 == c) { | 358 | if (c == -1) { |
| 359 | warn("asprintf"); | 359 | warn("asprintf"); |
| 360 | return (NULL); | 360 | return (NULL); |
| 361 | } else if (!http_write(req, c, http)) { | 361 | } else if (!http_write(req, c, http)) { |
| 362 | free(req); | 362 | free(req); |
| 363 | return (NULL); | 363 | return (NULL); |
| 364 | } else if (NULL != p && ! http_write(p, psz, http)) { | 364 | } else if (p != NULL && !http_write(p, psz, http)) { |
| 365 | free(req); | 365 | free(req); |
| 366 | return (NULL); | 366 | return (NULL); |
| 367 | } | 367 | } |
| @@ -369,7 +369,7 @@ http_open(const struct http *http, const void *p, size_t psz) | |||
| 369 | free(req); | 369 | free(req); |
| 370 | 370 | ||
| 371 | trans = calloc(1, sizeof(struct httpxfer)); | 371 | trans = calloc(1, sizeof(struct httpxfer)); |
| 372 | if (NULL == trans) | 372 | if (trans == NULL) |
| 373 | warn("calloc"); | 373 | warn("calloc"); |
| 374 | return (trans); | 374 | return (trans); |
| 375 | } | 375 | } |
| @@ -378,7 +378,7 @@ void | |||
| 378 | http_close(struct httpxfer *x) | 378 | http_close(struct httpxfer *x) |
| 379 | { | 379 | { |
| 380 | 380 | ||
| 381 | if (NULL == x) | 381 | if (x == NULL) |
| 382 | return; | 382 | return; |
| 383 | free(x->hbuf); | 383 | free(x->hbuf); |
| 384 | free(x->bbuf); | 384 | free(x->bbuf); |
| @@ -402,7 +402,7 @@ http_body_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 402 | void *pp; | 402 | void *pp; |
| 403 | size_t szp; | 403 | size_t szp; |
| 404 | 404 | ||
| 405 | if (NULL == sz) | 405 | if (sz == NULL) |
| 406 | sz = &szp; | 406 | sz = &szp; |
| 407 | 407 | ||
| 408 | /* Have we already parsed this? */ | 408 | /* Have we already parsed this? */ |
| @@ -420,10 +420,10 @@ http_body_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 420 | /* If less than sizeof(buf), at EOF. */ | 420 | /* If less than sizeof(buf), at EOF. */ |
| 421 | if ((ssz = http_read(buf, sizeof(buf), http)) < 0) | 421 | if ((ssz = http_read(buf, sizeof(buf), http)) < 0) |
| 422 | return (NULL); | 422 | return (NULL); |
| 423 | else if (0 == ssz) | 423 | else if (ssz == 0) |
| 424 | break; | 424 | break; |
| 425 | pp = realloc(trans->bbuf, trans->bbufsz + ssz); | 425 | pp = realloc(trans->bbuf, trans->bbufsz + ssz); |
| 426 | if (NULL == pp) { | 426 | if (pp == NULL) { |
| 427 | warn("realloc"); | 427 | warn("realloc"); |
| 428 | return (NULL); | 428 | return (NULL); |
| 429 | } | 429 | } |
| @@ -461,7 +461,7 @@ http_head_status(const struct http *http, struct httphead *h, size_t sz) | |||
| 461 | unsigned int code; | 461 | unsigned int code; |
| 462 | struct httphead *st; | 462 | struct httphead *st; |
| 463 | 463 | ||
| 464 | if (NULL == (st = http_head_get("Status", h, sz))) { | 464 | if ((st = http_head_get("Status", h, sz)) == NULL) { |
| 465 | warnx("%s: no status header", http->src.ip); | 465 | warnx("%s: no status header", http->src.ip); |
| 466 | return (-1); | 466 | return (-1); |
| 467 | } | 467 | } |
| @@ -470,7 +470,7 @@ http_head_status(const struct http *http, struct httphead *h, size_t sz) | |||
| 470 | if (rc < 0) { | 470 | if (rc < 0) { |
| 471 | warn("sscanf"); | 471 | warn("sscanf"); |
| 472 | return (-1); | 472 | return (-1); |
| 473 | } else if (1 != rc) { | 473 | } else if (rc != 1) { |
| 474 | warnx("%s: cannot convert status header", http->src.ip); | 474 | warnx("%s: cannot convert status header", http->src.ip); |
| 475 | return (-1); | 475 | return (-1); |
| 476 | } | 476 | } |
| @@ -496,7 +496,7 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 496 | struct httphead *h; | 496 | struct httphead *h; |
| 497 | char *cp, *ep, *ccp, *buf; | 497 | char *cp, *ep, *ccp, *buf; |
| 498 | 498 | ||
| 499 | if (NULL == sz) | 499 | if (sz == NULL) |
| 500 | sz = &szp; | 500 | sz = &szp; |
| 501 | 501 | ||
| 502 | /* | 502 | /* |
| @@ -505,13 +505,13 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 505 | * If we have errors on the stream, return NULL now. | 505 | * If we have errors on the stream, return NULL now. |
| 506 | */ | 506 | */ |
| 507 | 507 | ||
| 508 | if (NULL != trans->head) { | 508 | if (trans->head != NULL) { |
| 509 | *sz = trans->headsz; | 509 | *sz = trans->headsz; |
| 510 | return (trans->head); | 510 | return (trans->head); |
| 511 | } else if (trans->headok <= 0) | 511 | } else if (trans->headok <= 0) |
| 512 | return (NULL); | 512 | return (NULL); |
| 513 | 513 | ||
| 514 | if (NULL == (buf = strdup(trans->hbuf))) { | 514 | if ((buf = strdup(trans->hbuf)) == NULL) { |
| 515 | warn("strdup"); | 515 | warn("strdup"); |
| 516 | return (NULL); | 516 | return (NULL); |
| 517 | } | 517 | } |
| @@ -519,10 +519,10 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 519 | cp = buf; | 519 | cp = buf; |
| 520 | 520 | ||
| 521 | do { | 521 | do { |
| 522 | if (NULL != (cp = strstr(cp, "\r\n"))) | 522 | if ((cp = strstr(cp, "\r\n")) != NULL) |
| 523 | cp += 2; | 523 | cp += 2; |
| 524 | hsz++; | 524 | hsz++; |
| 525 | } while (NULL != cp); | 525 | } while (cp != NULL); |
| 526 | 526 | ||
| 527 | /* | 527 | /* |
| 528 | * Allocate headers, then step through the data buffer, parsing | 528 | * Allocate headers, then step through the data buffer, parsing |
| @@ -532,7 +532,7 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 532 | */ | 532 | */ |
| 533 | 533 | ||
| 534 | h = calloc(hsz, sizeof(struct httphead)); | 534 | h = calloc(hsz, sizeof(struct httphead)); |
| 535 | if (NULL == h) { | 535 | if (h == NULL) { |
| 536 | warn("calloc"); | 536 | warn("calloc"); |
| 537 | free(buf); | 537 | free(buf); |
| 538 | return (NULL); | 538 | return (NULL); |
| @@ -543,18 +543,18 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 543 | cp = buf; | 543 | cp = buf; |
| 544 | 544 | ||
| 545 | do { | 545 | do { |
| 546 | if (NULL != (ep = strstr(cp, "\r\n"))) { | 546 | if ((ep = strstr(cp, "\r\n")) != NULL) { |
| 547 | *ep = '\0'; | 547 | *ep = '\0'; |
| 548 | ep += 2; | 548 | ep += 2; |
| 549 | } | 549 | } |
| 550 | if (0 == hsz) { | 550 | if (hsz == 0) { |
| 551 | h[hsz].key = "Status"; | 551 | h[hsz].key = "Status"; |
| 552 | h[hsz++].val = cp; | 552 | h[hsz++].val = cp; |
| 553 | continue; | 553 | continue; |
| 554 | } | 554 | } |
| 555 | 555 | ||
| 556 | /* Skip bad headers. */ | 556 | /* Skip bad headers. */ |
| 557 | if (NULL == (ccp = strchr(cp, ':'))) { | 557 | if ((ccp = strchr(cp, ':')) == NULL) { |
| 558 | warnx("%s: header without separator", http->src.ip); | 558 | warnx("%s: header without separator", http->src.ip); |
| 559 | continue; | 559 | continue; |
| 560 | } | 560 | } |
| @@ -564,7 +564,7 @@ http_head_parse(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 564 | ccp++; | 564 | ccp++; |
| 565 | h[hsz].key = cp; | 565 | h[hsz].key = cp; |
| 566 | h[hsz++].val = ccp; | 566 | h[hsz++].val = ccp; |
| 567 | } while (NULL != (cp = ep)); | 567 | } while ((cp = ep) != NULL); |
| 568 | 568 | ||
| 569 | trans->headbuf = buf; | 569 | trans->headbuf = buf; |
| 570 | trans->head = h; | 570 | trans->head = h; |
| @@ -588,7 +588,7 @@ http_head_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 588 | void *pp; | 588 | void *pp; |
| 589 | size_t szp; | 589 | size_t szp; |
| 590 | 590 | ||
| 591 | if (NULL == sz) | 591 | if (sz == NULL) |
| 592 | sz = &szp; | 592 | sz = &szp; |
| 593 | 593 | ||
| 594 | /* Have we already parsed this? */ | 594 | /* Have we already parsed this? */ |
| @@ -614,10 +614,10 @@ http_head_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 614 | /* If less than sizeof(buf), at EOF. */ | 614 | /* If less than sizeof(buf), at EOF. */ |
| 615 | if ((ssz = http_read(buf, sizeof(buf), http)) < 0) | 615 | if ((ssz = http_read(buf, sizeof(buf), http)) < 0) |
| 616 | return (NULL); | 616 | return (NULL); |
| 617 | else if (0 == ssz) | 617 | else if (ssz == 0) |
| 618 | break; | 618 | break; |
| 619 | pp = realloc(trans->hbuf, trans->hbufsz + ssz); | 619 | pp = realloc(trans->hbuf, trans->hbufsz + ssz); |
| 620 | if (NULL == pp) { | 620 | if (pp == NULL) { |
| 621 | warn("realloc"); | 621 | warn("realloc"); |
| 622 | return (NULL); | 622 | return (NULL); |
| 623 | } | 623 | } |
| @@ -626,9 +626,9 @@ http_head_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 626 | trans->hbufsz += ssz; | 626 | trans->hbufsz += ssz; |
| 627 | /* Search for end of headers marker. */ | 627 | /* Search for end of headers marker. */ |
| 628 | ep = memmem(trans->hbuf, trans->hbufsz, "\r\n\r\n", 4); | 628 | ep = memmem(trans->hbuf, trans->hbufsz, "\r\n\r\n", 4); |
| 629 | } while (NULL == ep && sizeof(buf) == ssz); | 629 | } while (ep == NULL && ssz == sizeof(buf)); |
| 630 | 630 | ||
| 631 | if (NULL == ep) { | 631 | if (ep == NULL) { |
| 632 | warnx("%s: partial transfer", http->src.ip); | 632 | warnx("%s: partial transfer", http->src.ip); |
| 633 | return (NULL); | 633 | return (NULL); |
| 634 | } | 634 | } |
| @@ -653,7 +653,7 @@ http_head_read(const struct http *http, struct httpxfer *trans, size_t *sz) | |||
| 653 | ep += 4; | 653 | ep += 4; |
| 654 | trans->bbufsz = (trans->hbuf + trans->hbufsz) - ep; | 654 | trans->bbufsz = (trans->hbuf + trans->hbufsz) - ep; |
| 655 | trans->bbuf = malloc(trans->bbufsz); | 655 | trans->bbuf = malloc(trans->bbufsz); |
| 656 | if (NULL == trans->bbuf) { | 656 | if (trans->bbuf == NULL) { |
| 657 | warn("malloc"); | 657 | warn("malloc"); |
| 658 | return (NULL); | 658 | return (NULL); |
| 659 | } | 659 | } |
| @@ -668,7 +668,7 @@ void | |||
| 668 | http_get_free(struct httpget *g) | 668 | http_get_free(struct httpget *g) |
| 669 | { | 669 | { |
| 670 | 670 | ||
| 671 | if (NULL == g) | 671 | if (g == NULL) |
| 672 | return; | 672 | return; |
| 673 | http_close(g->xfer); | 673 | http_close(g->xfer); |
| 674 | http_free(g->http); | 674 | http_free(g->http); |
| @@ -688,17 +688,17 @@ http_get(const struct source *addrs, size_t addrsz, const char *domain, | |||
| 688 | char *bod, *headr; | 688 | char *bod, *headr; |
| 689 | 689 | ||
| 690 | h = http_alloc(addrs, addrsz, domain, port, path); | 690 | h = http_alloc(addrs, addrsz, domain, port, path); |
| 691 | if (NULL == h) | 691 | if (h == NULL) |
| 692 | return (NULL); | 692 | return (NULL); |
| 693 | 693 | ||
| 694 | if (NULL == (x = http_open(h, post, postsz))) { | 694 | if ((x = http_open(h, post, postsz)) == NULL) { |
| 695 | http_free(h); | 695 | http_free(h); |
| 696 | return (NULL); | 696 | return (NULL); |
| 697 | } else if (NULL == (headr = http_head_read(h, x, &headrsz))) { | 697 | } else if ((headr = http_head_read(h, x, &headrsz)) == NULL) { |
| 698 | http_close(x); | 698 | http_close(x); |
| 699 | http_free(h); | 699 | http_free(h); |
| 700 | return (NULL); | 700 | return (NULL); |
| 701 | } else if (NULL == (bod = http_body_read(h, x, &bodsz))) { | 701 | } else if ((bod = http_body_read(h, x, &bodsz)) == NULL) { |
| 702 | http_close(x); | 702 | http_close(x); |
| 703 | http_free(h); | 703 | http_free(h); |
| 704 | return (NULL); | 704 | return (NULL); |
| @@ -706,7 +706,7 @@ http_get(const struct source *addrs, size_t addrsz, const char *domain, | |||
| 706 | 706 | ||
| 707 | http_disconnect(h); | 707 | http_disconnect(h); |
| 708 | 708 | ||
| 709 | if (NULL == (head = http_head_parse(h, x, &headsz))) { | 709 | if ((head = http_head_parse(h, x, &headsz)) == NULL) { |
| 710 | http_close(x); | 710 | http_close(x); |
| 711 | http_free(h); | 711 | http_free(h); |
| 712 | return (NULL); | 712 | return (NULL); |
| @@ -716,7 +716,7 @@ http_get(const struct source *addrs, size_t addrsz, const char *domain, | |||
| 716 | return (NULL); | 716 | return (NULL); |
| 717 | } | 717 | } |
| 718 | 718 | ||
| 719 | if (NULL == (g = calloc(1, sizeof(struct httpget)))) { | 719 | if ((g = calloc(1, sizeof(struct httpget))) == NULL) { |
| 720 | warn("calloc"); | 720 | warn("calloc"); |
| 721 | http_close(x); | 721 | http_close(x); |
| 722 | http_free(h); | 722 | http_free(h); |
| @@ -767,7 +767,7 @@ main(void) | |||
| 767 | NULL, 0); | 767 | NULL, 0); |
| 768 | #endif | 768 | #endif |
| 769 | 769 | ||
| 770 | if (NULL == g) | 770 | if (g == NULL) |
| 771 | errx(EXIT_FAILURE, "http_get"); | 771 | errx(EXIT_FAILURE, "http_get"); |
| 772 | 772 | ||
| 773 | httph = http_head_parse(g->http, g->xfer, &httphsz); | 773 | httph = http_head_parse(g->http, g->xfer, &httphsz); |
