commit 7277bb7dc2971fad2a51b7975df85dda1df4c936 from: Omar Polo date: Sat Sep 10 09:21:09 2022 UTC make config fields `chroot' and `user' fixed-size commit - aae8f6bf2b6be18c8bb4fc46c2df679110fe9d96 commit + 7277bb7dc2971fad2a51b7975df85dda1df4c936 blob - 83e3be72dd9acb9971da0d31302935cac85e2f8f blob + 92ff26b20ef67f8d5ebebd288adc52ad7c0eb4a0 --- gmid.c +++ gmid.c @@ -205,9 +205,6 @@ init_config(void) init_mime(&conf.mime); - conf.chroot = NULL; - conf.user = NULL; - conf.prefork = 3; } @@ -224,8 +221,6 @@ free_config(void) v = conf.verbose; free_mime(&conf.mime); - free(conf.chroot); - free(conf.user); memset(&conf, 0, sizeof(conf)); conf.verbose = v; @@ -328,15 +323,15 @@ drop_priv(void) { struct passwd *pw = NULL; - if (conf.chroot != NULL && conf.user == NULL) + if (*conf.chroot != '\0' && *conf.user == '\0') fatal("can't chroot without an user to switch to after."); - if (conf.user != NULL) { + if (*conf.user != '\0') { if ((pw = getpwnam(conf.user)) == NULL) fatal("can't find user %s", conf.user); } - if (conf.chroot != NULL) { + if (*conf.chroot != '\0') { if (chroot(conf.chroot) != 0 || chdir("/") != 0) fatal("%s: %s", conf.chroot, strerror(errno)); } blob - 38b99ad306905dfa7d5831ed26d91fc0102d364c blob + 0997699cdcd83851c6c7db9f59fa88aecdc06302 --- gmid.h +++ gmid.h @@ -203,8 +203,8 @@ struct conf { int ipv6; uint32_t protos; struct mime mime; - char *chroot; - char *user; + char chroot[PATH_MAX]; + char user[LOGIN_NAME_MAX]; int prefork; }; blob - 96ab053d9087b7965cba97623de12cd5f68f3d4d blob + 9eac0c47a113711a95bce5468556637917a44385 --- parse.y +++ parse.y @@ -212,7 +212,12 @@ varset : STRING '=' string { } ; -option : CHROOT string { conf.chroot = $2; } +option : CHROOT string { + if (strlcpy(conf.chroot, $2, sizeof(conf.chroot)) >= + sizeof(conf.chroot)) + yyerror("chroot path too long"); + free($2); + } | IPV6 bool { conf.ipv6 = $2; } | MIME STRING string { yywarn("`mime MIME EXT' is deprecated and will be " @@ -235,7 +240,12 @@ option : CHROOT string { conf.chroot = $2; } yyerror("invalid protocols string \"%s\"", $2); free($2); } - | USER string { conf.user = $2; } + | USER string { + if (strlcpy(conf.user, $2, sizeof(conf.user)) >= + sizeof(conf.user)) + yyerror("user name too long"); + free($2); + } ; vhost : SERVER string { @@ -949,14 +959,14 @@ print_conf(void) /* struct envlist *e; */ /* struct alist *a; */ - if (conf.chroot != NULL) + if (*conf.chroot != '\0') printf("chroot \"%s\"\n", conf.chroot); printf("ipv6 %s\n", conf.ipv6 ? "on" : "off"); /* XXX: defined mimes? */ printf("port %d\n", conf.port); printf("prefork %d\n", conf.prefork); /* XXX: protocols? */ - if (conf.user != NULL) + if (*conf.user != '\0') printf("user \"%s\"\n", conf.user); TAILQ_FOREACH(h, &hosts, vhosts) {