Commit Diff
Diff:
7277bb7dc2971fad2a51b7975df85dda1df4c936
aa9543b9fd1963d86f63fda13addb356f9039c37
Commit:
aa9543b9fd1963d86f63fda13addb356f9039c37
Tree:
e01438402f1c2dfd9aa5d34a54701681fcf62c68
Author:
Omar Polo <op@omarpolo.com>
Date:
Sat Sep 10 09:40:05 2022 UTC
Message:
make the mime types fixed-sized too
commit - 7277bb7dc2971fad2a51b7975df85dda1df4c936
commit + aa9543b9fd1963d86f63fda13addb356f9039c37
blob - 0997699cdcd83851c6c7db9f59fa88aecdc06302
blob + 3d2540328660d03c37085e73e52452cd378f9786
--- gmid.h
+++ gmid.h
@@ -70,6 +70,9 @@
#define DOMAIN_NAME_LEN (253+1)
#define LABEL_LEN (63+1)
+#define MEDIATYPE_NAMEMAX 128 /* file name extension */
+#define MEDIATYPE_TYPEMAX 128 /* length of type/subtype */
+
#define FCGI_MAX 32
#define PROC_MAX 16
@@ -175,8 +178,8 @@ struct etm { /* extension to mime */
};
struct etm { /* extension to mime */
- char *mime;
- char *ext;
+ char mime[MEDIATYPE_TYPEMAX];
+ char ext[MEDIATYPE_NAMEMAX];
};
struct mime {
blob - e70b3fe8258c9cdeb09291f70412ada84d87dd89
blob + ad338f0dfabf4f046f9d7b62e998cf6200680282
--- mime.c
+++ mime.c
@@ -35,7 +35,6 @@ add_mime(struct mime *mime, const char *mt, const char
int
add_mime(struct mime *mime, const char *mt, const char *ext)
{
- char *mimetype, *extension;
struct etm *t;
size_t newcap;
@@ -49,15 +48,11 @@ add_mime(struct mime *mime, const char *mt, const char
mime->cap = newcap;
}
- if ((mimetype = strdup(mt)) == NULL)
+ t = &mime->t[mime->len];
+ if (strlcpy(t->mime, mt, sizeof(t->mime)) >= sizeof(t->mime))
return -1;
- if ((extension = strdup(ext)) == NULL) {
- free(mimetype);
+ if (strlcpy(t->ext, ext, sizeof(t->ext)) >= sizeof(t->ext))
return -1;
- }
-
- mime->t[mime->len].mime = mimetype;
- mime->t[mime->len].ext = extension;
mime->len++;
return 0;
}
@@ -157,12 +152,5 @@ free_mime(struct mime *m)
void
free_mime(struct mime *m)
{
- struct etm *t;
-
- for (t = m->t; t->mime != NULL; ++t) {
- free(t->mime);
- free(t->ext);
- }
-
free(m->t);
}
blob - 9eac0c47a113711a95bce5468556637917a44385
blob + 6a664f93c5375543aa7f3cf6a5573a3b9312ed1d
--- parse.y
+++ parse.y
@@ -225,6 +225,8 @@ option : CHROOT string {
"`types' block.");
if (add_mime(&conf.mime, $2, $3) == -1)
err(1, "add_mime");
+ free($2);
+ free($3);
}
| MAP string TOEXT string {
yywarn("`map mime to-ext' is deprecated and will be "
@@ -232,6 +234,8 @@ option : CHROOT string {
"`types' block.");
if (add_mime(&conf.mime, $2, $4) == -1)
err(1, "add_mime");
+ free($2);
+ free($4);
}
| PORT NUM { conf.port = check_port_num($2); }
| PREFORK NUM { conf.prefork = check_prefork_num($2); }
@@ -477,7 +481,10 @@ mediaoptsl : STRING { current_media = $1; } medianames
| mediaoptsl nl
;
-mediaoptsl : STRING { current_media = $1; } medianames_l optsemicolon
+mediaoptsl : STRING {
+ free(current_media);
+ current_media = $1;
+ } medianames_l optsemicolon
| include
;
@@ -488,6 +495,7 @@ medianamesl : numberstring {
medianamesl : numberstring {
if (add_mime(&conf.mime, current_media, $1) == -1)
err(1, "add_mime");
+ free($1);
}
;
Omar Polo