Avoid magic string lengths

parent 8f23ac49
......@@ -83,18 +83,18 @@ tus_file_final_concat_parse(const char *spec)
while (spec != NULL) {
while (*spec == ' ')
spec++;
if (strncmp(spec, "http", 4) == 0) {
spec += 4;
if (TOK(spec, "http")) {
AN(spec);
if (*spec == 's')
spec++;
if (strncmp(spec, "://", 3) != 0)
if (! TOK(spec, "://"))
goto err;
spec += 3;
p = strchr(spec, '/');
if (p == NULL)
goto err;
spec = p;
}
AN(spec);
if (*spec != '/')
goto err;
p = strchr(spec, ' ');
......@@ -862,7 +862,7 @@ tus_file_load(struct VPFX(tus_server) *srv)
dir = fdopendir(dup(basefd));
AN(dir);
while ((ent = readdir(dir)) != NULL) {
if (strncmp(ent->d_name, TUS_FILE_PFX, strlen(TUS_FILE_PFX)))
if (STRNCMP(ent->d_name, TUS_FILE_PFX))
continue;
if (ent->d_type != DT_REG)
continue;
......
......@@ -40,6 +40,26 @@
*/
extern struct VSC_lck *lck_fcore;
/* ============================================================
* Util - could move elsewhere
*/
#define STRNCMP(var, literal) \
strncmp(var, literal, strlen(literal))
/*
* lint:
* 820: Boolean test of a parenthesized assignment
* 774: Boolean within 'right side of && within if' always
* evaluates to True
*/
#define TOK(var, literal) \
(STRNCMP(var, literal) == 0 && ((var) += strlen(literal)) \
/*lint -e(820,774)*/)
/* ============================================================
* tus_file
*/
#define TUS_PATH_MAX ((size_t)PATH_MAX)
#define TUS_METADATA_MAX ((size_t)2048) // ballpark of AWS S3 metadata
......
......@@ -281,12 +281,11 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
}
if (http_GetHdr(ctx->http_req, hdr_concat, &concat)) {
if (strcmp(concat, "partial") == 0) {
if (strcmp(concat, "partial") == 0)
type = TUS_PARTIAL;
} else if (strncmp(concat, "final;", 6) == 0) {
else if (TOK(concat, "final;"))
type = TUS_FINAL;
concat += 6;
} else {
else {
r->s.status = 400;
return (0);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment