[vlc-devel] [PATCH 07/12] http_auth: Remove VLA usages
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Tue Dec 8 15:19:11 CET 2020
---
src/network/http_auth.c | 34 ++++++++++++++++++----------------
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/src/network/http_auth.c b/src/network/http_auth.c
index 599fda6286..50728670c9 100644
--- a/src/network/http_auth.c
+++ b/src/network/http_auth.c
@@ -44,8 +44,10 @@
*****************************************************************************/
static char *AuthGetParam( const char *psz_header, const char *psz_param )
{
- char psz_what[strlen(psz_param)+3];
- sprintf( psz_what, "%s=\"", psz_param );
+ char* psz_what;
+ char* psz_res = NULL;
+ if (asprintf(&psz_what, "%s=\"", psz_param) < 0)
+ return NULL;
psz_header = strstr( psz_header, psz_what );
if ( psz_header )
{
@@ -53,19 +55,20 @@ static char *AuthGetParam( const char *psz_header, const char *psz_param )
psz_header += strlen( psz_what );
psz_end = strchr( psz_header, '"' );
if ( !psz_end ) /* Invalid since we should have a closing quote */
- return strdup( psz_header );
- return strndup( psz_header, psz_end - psz_header );
- }
- else
- {
- return NULL;
+ psz_res = strdup( psz_header );
+ else
+ psz_res = strndup( psz_header, psz_end - psz_header );
}
+ free(psz_what);
+ return psz_res;
}
static char *AuthGetParamNoQuotes( const char *psz_header, const char *psz_param )
{
- char psz_what[strlen(psz_param)+2];
- sprintf( psz_what, "%s=", psz_param );
+ char* psz_what;
+ char* psz_res = NULL;
+ if (asprintf(&psz_what, "%s=", psz_param) < 0)
+ return NULL;
psz_header = strstr( psz_header, psz_what );
if ( psz_header )
{
@@ -75,13 +78,12 @@ static char *AuthGetParamNoQuotes( const char *psz_header, const char *psz_param
/* XXX: Do we need to filter out trailing space between the value and
* the comma/end of line? */
if ( !psz_end ) /* Can be valid if this is the last parameter */
- return strdup( psz_header );
- return strndup( psz_header, psz_end - psz_header );
- }
- else
- {
- return NULL;
+ psz_res = strdup( psz_header );
+ else
+ psz_res = strndup( psz_header, psz_end - psz_header );
}
+ free(psz_what);
+ return psz_res;
}
static char *GenerateCnonce()
--
2.29.2
More information about the vlc-devel
mailing list