Avoid magic string lengths

parent 8f23ac49
...@@ -83,18 +83,18 @@ tus_file_final_concat_parse(const char *spec) ...@@ -83,18 +83,18 @@ tus_file_final_concat_parse(const char *spec)
while (spec != NULL) { while (spec != NULL) {
while (*spec == ' ') while (*spec == ' ')
spec++; spec++;
if (strncmp(spec, "http", 4) == 0) { if (TOK(spec, "http")) {
spec += 4; AN(spec);
if (*spec == 's') if (*spec == 's')
spec++; spec++;
if (strncmp(spec, "://", 3) != 0) if (! TOK(spec, "://"))
goto err; goto err;
spec += 3;
p = strchr(spec, '/'); p = strchr(spec, '/');
if (p == NULL) if (p == NULL)
goto err; goto err;
spec = p; spec = p;
} }
AN(spec);
if (*spec != '/') if (*spec != '/')
goto err; goto err;
p = strchr(spec, ' '); p = strchr(spec, ' ');
...@@ -862,7 +862,7 @@ tus_file_load(struct VPFX(tus_server) *srv) ...@@ -862,7 +862,7 @@ tus_file_load(struct VPFX(tus_server) *srv)
dir = fdopendir(dup(basefd)); dir = fdopendir(dup(basefd));
AN(dir); AN(dir);
while ((ent = readdir(dir)) != NULL) { 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; continue;
if (ent->d_type != DT_REG) if (ent->d_type != DT_REG)
continue; continue;
......
...@@ -40,6 +40,26 @@ ...@@ -40,6 +40,26 @@
*/ */
extern struct VSC_lck *lck_fcore; 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_PATH_MAX ((size_t)PATH_MAX)
#define TUS_METADATA_MAX ((size_t)2048) // ballpark of AWS S3 metadata #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, ...@@ -281,12 +281,11 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
} }
if (http_GetHdr(ctx->http_req, hdr_concat, &concat)) { if (http_GetHdr(ctx->http_req, hdr_concat, &concat)) {
if (strcmp(concat, "partial") == 0) { if (strcmp(concat, "partial") == 0)
type = TUS_PARTIAL; type = TUS_PARTIAL;
} else if (strncmp(concat, "final;", 6) == 0) { else if (TOK(concat, "final;"))
type = TUS_FINAL; type = TUS_FINAL;
concat += 6; else {
} else {
r->s.status = 400; r->s.status = 400;
return (0); 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