@@ -518,37 +518,46 @@ char *
518
518
sss_tc_fqname (TALLOC_CTX * mem_ctx , struct sss_names_ctx * nctx ,
519
519
struct sss_domain_info * domain , const char * name )
520
520
{
521
- if (domain == NULL || nctx == NULL ) return NULL ;
521
+ if (domain == NULL || nctx == NULL ) {
522
+ errno = EINVAL ;
523
+ return NULL ;
524
+ }
522
525
523
526
return sss_tc_fqname2 (mem_ctx , nctx , domain -> name ,
524
527
calc_flat_name (domain ), name );
525
528
}
526
529
527
- static void
528
- safe_talloc_callback (void * data ,
529
- const char * piece ,
530
- size_t len )
531
- {
532
- char * * output = data ;
533
- if (* output != NULL )
534
- * output = talloc_strndup_append (* output , piece , len );
535
- }
536
-
537
530
char *
538
531
sss_tc_fqname2 (TALLOC_CTX * mem_ctx , struct sss_names_ctx * nctx ,
539
532
const char * domain_name , const char * flat_dom_name ,
540
533
const char * name )
541
534
{
542
- const char * args [] = { name , domain_name , flat_dom_name , NULL };
543
535
char * output ;
536
+ int fqdn_len , len ;
544
537
545
- if (nctx == NULL ) return NULL ;
538
+ if (nctx == NULL ) {
539
+ errno = EINVAL ;
540
+ return NULL ;
541
+ }
546
542
547
- output = talloc_strdup (mem_ctx , "" );
548
- if (safe_format_string_cb (safe_talloc_callback , & output , nctx -> fq_fmt , args , 3 ) < 0 )
549
- output = NULL ;
550
- else if (output == NULL )
543
+ fqdn_len = safe_format_string (NULL , 0 , nctx -> fq_fmt ,
544
+ name , domain_name , flat_dom_name , NULL );
545
+ if (fqdn_len <= 0 ) {
546
+ errno = EINVAL ;
547
+ return NULL ;
548
+ }
549
+ output = talloc_size (mem_ctx , fqdn_len + 1 );
550
+ if (output == NULL ) {
551
551
errno = ENOMEM ;
552
+ return NULL ;
553
+ }
554
+ len = safe_format_string (output , fqdn_len + 1 , nctx -> fq_fmt ,
555
+ name , domain_name , flat_dom_name , NULL );
556
+ if (len != fqdn_len ) {
557
+ talloc_free (output );
558
+ errno = EINVAL ;
559
+ return NULL ;
560
+ }
552
561
return output ;
553
562
}
554
563
0 commit comments