]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ssl: check allocation in parse npn/sni
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 1 Jun 2021 09:54:23 +0000 (11:54 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 18 Jun 2021 14:42:25 +0000 (16:42 +0200)
These checks are especially required now as this function will be used
at runtime for dynamic servers.

src/cfgparse-ssl.c

index 2adb92e85d97cefe8eef3b31cb0582a0236129e7..11af3aac437e18dabd01d536687ec30bba805a40 100644 (file)
@@ -1270,6 +1270,11 @@ static int srv_parse_npn(char **args, int *cur_arg, struct proxy *px, struct ser
         */
        newsrv->ssl_ctx.npn_len = strlen(args[*cur_arg + 1]) + 1;
        newsrv->ssl_ctx.npn_str = calloc(1, newsrv->ssl_ctx.npn_len + 1);
+       if (!newsrv->ssl_ctx.npn_str) {
+               memprintf(err, "out of memory");
+               return ERR_ALERT | ERR_FATAL;
+       }
+
        memcpy(newsrv->ssl_ctx.npn_str + 1, args[*cur_arg + 1],
            newsrv->ssl_ctx.npn_len);
 
@@ -1590,6 +1595,10 @@ static int srv_parse_sni(char **args, int *cur_arg, struct proxy *px, struct ser
 
        free(newsrv->sni_expr);
        newsrv->sni_expr = strdup(arg);
+       if (!newsrv->sni_expr) {
+               memprintf(err, "out of memory");
+               return ERR_ALERT | ERR_FATAL;
+       }
 
        return 0;
 #endif