From 2e375aad04d047e12468f93300ad7e42a8a03ff3 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Fri, 15 Dec 2023 10:14:11 +0100 Subject: treewide: use asprintf to construct strings The asprintf function is considered as given for current code already. Use it instead of calling malloc + strcpy + strcat manually. Reported-by: Benny Baumann Signed-off-by: Tobias Stoeckmann --- conf/pam_conv1/pam_conv_y.y | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'conf') diff --git a/conf/pam_conv1/pam_conv_y.y b/conf/pam_conv1/pam_conv_y.y index 72a5dab3..e2cf85c3 100644 --- a/conf/pam_conv1/pam_conv_y.y +++ b/conf/pam_conv1/pam_conv_y.y @@ -78,8 +78,10 @@ line /* $1 = service-name */ yyerror("Appending to " PAM_D "/%s", $1); - filename = malloc(strlen($1) + sizeof(PAM_D) + 6); - sprintf(filename, PAM_D_FILE_FMT, $1); + if (asprintf(&filename, PAM_D_FILE_FMT, $1) < 0) { + yyerror("unable to create filename - aborting"); + exit(1); + } conf = fopen(filename, "r"); if (conf == NULL) { /* new file */ @@ -140,12 +142,11 @@ tokenls $$=NULL; } | tokenls tok { - int len; - if ($1) { - len = strlen($1) + strlen($2) + 2; - $$ = malloc(len); - sprintf($$,"%s %s",$1,$2); + if (asprintf(&$$, "%s %s", $1, $2) < 0) { + yyerror("failed to assemble tokenls"); + exit(1); + } free($1); free($2); } else { -- cgit v1.2.3