mirror of
https://github.com/bdnugget/kcgi.git
synced 2026-11-07 05:47:27 +00:00
Replace XMALLOC and XCALLOC and use some style(9) while there.
This commit is contained in:
1 parent
05f95f41ab
commit
ecc091c29b
8 files changed
+44
-44
No files matched your search
@@ -77,7 +77,7 @@ base64buf(char *enc, const char *str, size_t len)
|
||||
}
|
||||
|
||||
*p++ = '\0';
|
||||
return(p - enc);
|
||||
return (p - enc);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -88,27 +88,31 @@ khttpbasic_validate(const struct kreq *req,
|
||||
size_t sz;
|
||||
int rc;
|
||||
|
||||
if (KAUTH_BASIC != req->rawauth.type)
|
||||
return(-1);
|
||||
else if (KMETHOD__MAX == req->method)
|
||||
return(-1);
|
||||
else if (0 == req->rawauth.authorised)
|
||||
return(-1);
|
||||
if (req->rawauth.type != KAUTH_BASIC)
|
||||
return (-1);
|
||||
else if (req->method == KMETHOD__MAX)
|
||||
return (-1);
|
||||
else if (req->rawauth.authorised == 0)
|
||||
return (-1);
|
||||
|
||||
/* Make sure we don't bail on memory allocation. */
|
||||
|
||||
sz = strlen(user) + 1 + strlen(pass) + 1;
|
||||
if (NULL == (buf = XMALLOC(sz)))
|
||||
return(-1);
|
||||
if ((buf = kxmalloc(sz)) == NULL)
|
||||
return (-1);
|
||||
|
||||
sz = snprintf(buf, sz, "%s:%s", user, pass);
|
||||
if (NULL == (enc = XMALLOC(base64len(sz)))) {
|
||||
if ((enc = kxmalloc(base64len(sz))) == NULL) {
|
||||
free(buf);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
base64buf(enc, buf, sz);
|
||||
rc = 0 == strcmp(enc, req->rawauth.d.basic.response);
|
||||
rc = strcmp(enc, req->rawauth.d.basic.response) == 0;
|
||||
|
||||
free(enc);
|
||||
free(buf);
|
||||
return(rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@@ -333,7 +333,7 @@ scanbuf(size_t len, size_t *szp)
|
||||
|
||||
/* Allocate the entire buffer here. */
|
||||
|
||||
if ((p = XMALLOC(len + 1)) == NULL)
|
||||
if ((p = kxmalloc(len + 1)) == NULL)
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
/*
|
||||
@@ -1577,7 +1577,7 @@ kworker_child(int wfd,
|
||||
envsz++;
|
||||
|
||||
if (envsz) {
|
||||
envs = XCALLOC(envsz, sizeof(struct env));
|
||||
envs = kxcalloc(envsz, sizeof(struct env));
|
||||
if (envs == NULL)
|
||||
return KCGI_ENOMEM;
|
||||
}
|
||||
@@ -1971,7 +1971,7 @@ kworker_fcgi_params(struct fcgi_buf *buf, const struct fcgi_hdr *hdr,
|
||||
return KCGI_ENOMEM;
|
||||
|
||||
*envs = ptr;
|
||||
(*envs)[i].key = XMALLOC(keysz + 1);
|
||||
(*envs)[i].key = kxmalloc(keysz + 1);
|
||||
if ((*envs)[i].key == NULL)
|
||||
return KCGI_ENOMEM;
|
||||
|
||||
@@ -1986,7 +1986,7 @@ kworker_fcgi_params(struct fcgi_buf *buf, const struct fcgi_hdr *hdr,
|
||||
|
||||
/* Copy the value. */
|
||||
|
||||
(*envs)[i].val = XMALLOC(valsz + 1);
|
||||
(*envs)[i].val = kxmalloc(valsz + 1);
|
||||
if ((*envs)[i].val == NULL)
|
||||
return KCGI_ENOMEM;
|
||||
|
||||
|
||||
@@ -99,8 +99,8 @@ int kxasprintf(const char *, int,
|
||||
__attribute__((format(printf, 4, 5)));
|
||||
int kxvasprintf(const char *, int,
|
||||
char **, const char *, va_list);
|
||||
void *kxcalloc(const char *, int, size_t, size_t);
|
||||
void *kxmalloc(const char *, int, size_t);
|
||||
void *kxcalloc(size_t, size_t);
|
||||
void *kxmalloc(size_t);
|
||||
void *kxrealloc(void *, size_t);
|
||||
void *kxreallocarray(void *, size_t, size_t);
|
||||
char *kxstrdup(const char *);
|
||||
@@ -108,10 +108,6 @@ char *kxstrdup(const char *);
|
||||
kxasprintf(__FILE__, __LINE__, (_p), __VA_ARGS__)
|
||||
#define XVASPRINTF(_p, _fmt, _va) \
|
||||
kxvasprintf(__FILE__, __LINE__, (_p), _fmt, _va)
|
||||
#define XCALLOC(_nm, _sz) \
|
||||
kxcalloc(__FILE__, __LINE__, (_nm), (_sz))
|
||||
#define XMALLOC(_sz) \
|
||||
kxmalloc(__FILE__, __LINE__, (_sz))
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
||||
@@ -536,7 +536,7 @@ khttp_fcgi_initx(struct kfcgi **fcgip,
|
||||
|
||||
/* Now allocate our device. */
|
||||
|
||||
*fcgip = fcgi = XCALLOC(1, sizeof(struct kfcgi));
|
||||
*fcgip = fcgi = kxcalloc(1, sizeof(struct kfcgi));
|
||||
if (fcgi == NULL) {
|
||||
close(sock_ctl[KWORKER_PARENT]);
|
||||
close(work_dat[KWORKER_PARENT]);
|
||||
@@ -678,19 +678,19 @@ khttp_fcgi_parse(struct kfcgi *fcgi, struct kreq *req)
|
||||
}
|
||||
|
||||
if (fcgi->keysz) {
|
||||
req->cookiemap = XCALLOC
|
||||
req->cookiemap = kxcalloc
|
||||
(fcgi->keysz, sizeof(struct kpair *));
|
||||
if (req->cookiemap == NULL)
|
||||
goto err;
|
||||
req->cookienmap = XCALLOC
|
||||
req->cookienmap = kxcalloc
|
||||
(fcgi->keysz, sizeof(struct kpair *));
|
||||
if (req->cookienmap == NULL)
|
||||
goto err;
|
||||
req->fieldmap = XCALLOC
|
||||
req->fieldmap = kxcalloc
|
||||
(fcgi->keysz, sizeof(struct kpair *));
|
||||
if (req->fieldmap == NULL)
|
||||
goto err;
|
||||
req->fieldnmap = XCALLOC
|
||||
req->fieldnmap = kxcalloc
|
||||
(fcgi->keysz, sizeof(struct kpair *));
|
||||
if (req->fieldnmap == NULL)
|
||||
goto err;
|
||||
|
||||
@@ -391,7 +391,7 @@ kcalloc(size_t nm, size_t sz)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if ((p = XCALLOC(nm, sz)) != NULL)
|
||||
if ((p = kxcalloc(nm, sz)) != NULL)
|
||||
return p;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -404,7 +404,7 @@ kmalloc(size_t sz)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if ((p = XMALLOC(sz)) != NULL)
|
||||
if ((p = kxmalloc(sz)) != NULL)
|
||||
return p;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -441,7 +441,7 @@ khttp_urlencode(const char *cp)
|
||||
kutil_warnx(NULL, NULL, "multiplicative overflow");
|
||||
return NULL;
|
||||
}
|
||||
if ((p = XCALLOC(sz, 3)) == NULL)
|
||||
if ((p = kxcalloc(sz, 3)) == NULL)
|
||||
return NULL;
|
||||
|
||||
for (cur = 0; (ch = *cp) != '\0'; cp++) {
|
||||
@@ -1019,16 +1019,16 @@ khttp_parsex(struct kreq *req,
|
||||
goto err;
|
||||
|
||||
if (keysz) {
|
||||
req->cookiemap = XCALLOC(keysz, sizeof(struct kpair *));
|
||||
req->cookiemap = kxcalloc(keysz, sizeof(struct kpair *));
|
||||
if (req->cookiemap == NULL)
|
||||
goto err;
|
||||
req->cookienmap = XCALLOC(keysz, sizeof(struct kpair *));
|
||||
req->cookienmap = kxcalloc(keysz, sizeof(struct kpair *));
|
||||
if (req->cookienmap == NULL)
|
||||
goto err;
|
||||
req->fieldmap = XCALLOC(keysz, sizeof(struct kpair *));
|
||||
req->fieldmap = kxcalloc(keysz, sizeof(struct kpair *));
|
||||
if (req->fieldmap == NULL)
|
||||
goto err;
|
||||
req->fieldnmap = XCALLOC(keysz, sizeof(struct kpair *));
|
||||
req->fieldnmap = kxcalloc(keysz, sizeof(struct kpair *));
|
||||
if (req->fieldnmap == NULL)
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ linebuf_init(struct kdata *p)
|
||||
if (p->linebuf == NULL) {
|
||||
p->linebufsz = 0;
|
||||
p->linebufpos = 0;
|
||||
if ((p->linebuf = XMALLOC(BUFSIZ)) == NULL)
|
||||
if ((p->linebuf = kxmalloc(BUFSIZ)) == NULL)
|
||||
return 0;
|
||||
p->linebuf[0] = '\0';
|
||||
p->linebufsz = BUFSIZ;
|
||||
@@ -417,7 +417,7 @@ kdata_alloc(int control, int fcgi, uint16_t requestId,
|
||||
{
|
||||
struct kdata *p;
|
||||
|
||||
if ((p = XCALLOC(1, sizeof(struct kdata))) == NULL)
|
||||
if ((p = kxcalloc(1, sizeof(struct kdata))) == NULL)
|
||||
return NULL;
|
||||
|
||||
p->debugging = debugging;
|
||||
@@ -427,7 +427,7 @@ kdata_alloc(int control, int fcgi, uint16_t requestId,
|
||||
|
||||
if (opts->sndbufsz > 0) {
|
||||
p->outbufsz = opts->sndbufsz;
|
||||
if ((p->outbuf = XMALLOC(p->outbufsz)) == NULL) {
|
||||
if ((p->outbuf = kxmalloc(p->outbufsz)) == NULL) {
|
||||
free(p);
|
||||
return NULL;
|
||||
}
|
||||
@@ -677,7 +677,7 @@ kcgi_writer_get(struct kreq *r, int type)
|
||||
abort();
|
||||
}
|
||||
|
||||
if ((p = XMALLOC(sizeof(struct kcgi_writer))) != NULL)
|
||||
if ((p = kxmalloc(sizeof(struct kcgi_writer))) != NULL)
|
||||
p->kdata = r->kdata;
|
||||
|
||||
return p;
|
||||
|
||||
@@ -228,7 +228,7 @@ kworker_parent(int fd, struct kreq *r, int eofok, size_t mimesz)
|
||||
}
|
||||
|
||||
if (r->reqsz) {
|
||||
r->reqs = XCALLOC(r->reqsz, sizeof(struct khead));
|
||||
r->reqs = kxcalloc(r->reqsz, sizeof(struct khead));
|
||||
if (r->reqs == NULL) {
|
||||
ke = KCGI_ENOMEM;
|
||||
goto out;
|
||||
@@ -293,7 +293,7 @@ kworker_parent(int fd, struct kreq *r, int eofok, size_t mimesz)
|
||||
goto out;
|
||||
} else if (dgsz == MD5_DIGEST_LENGTH) {
|
||||
/* This is a binary value. */
|
||||
if ((r->rawauth.digest = XMALLOC(dgsz)) == NULL)
|
||||
if ((r->rawauth.digest = kxmalloc(dgsz)) == NULL)
|
||||
goto out;
|
||||
if (fullread(fd, r->rawauth.digest, dgsz, 0, &ke) < 0) {
|
||||
kutil_warnx(NULL, NULL, "failed read digest");
|
||||
|
||||
+3
-3
@@ -63,7 +63,7 @@ kxasprintf(const char *file, int line, char **p, const char *fmt, ...)
|
||||
}
|
||||
|
||||
void *
|
||||
kxcalloc(const char *file, int line, size_t nm, size_t sz)
|
||||
kxcalloc(size_t nm, size_t sz)
|
||||
{
|
||||
void *p;
|
||||
|
||||
@@ -78,7 +78,7 @@ kxcalloc(const char *file, int line, size_t nm, size_t sz)
|
||||
}
|
||||
|
||||
void *
|
||||
kxmalloc(const char *file, int line, size_t sz)
|
||||
kxmalloc(size_t sz)
|
||||
{
|
||||
void *p;
|
||||
|
||||
@@ -457,7 +457,7 @@ fullreadwordsz(int fd, char **cp, size_t *sz)
|
||||
|
||||
/* TODO: check additive overflow of "sz + 1". */
|
||||
|
||||
if ((*cp = XMALLOC(*sz + 1)) == NULL) {
|
||||
if ((*cp = kxmalloc(*sz + 1)) == NULL) {
|
||||
*sz = 0;
|
||||
return KCGI_ENOMEM;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user