@@ -68,20 +68,6 @@ static void imap_warn(const char *, ...);
68
68
69
69
static char * next_arg (char * * );
70
70
71
- static int nfvasprintf (char * * strp , const char * fmt , va_list ap )
72
- {
73
- int len ;
74
- char tmp [8192 ];
75
-
76
- len = vsnprintf (tmp , sizeof (tmp ), fmt , ap );
77
- if (len < 0 )
78
- die ("Fatal: Out of memory" );
79
- if (len >= sizeof (tmp ))
80
- die ("imap command overflow!" );
81
- * strp = xmemdupz (tmp , len );
82
- return len ;
83
- }
84
-
85
71
struct imap_server_conf {
86
72
const char * name ;
87
73
const char * tunnel ;
@@ -503,11 +489,11 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
503
489
{
504
490
struct imap * imap = ctx -> imap ;
505
491
struct imap_cmd * cmd ;
506
- int n , bufl ;
507
- char buf [ 1024 ] ;
492
+ int n ;
493
+ struct strbuf buf = STRBUF_INIT ;
508
494
509
495
cmd = xmalloc (sizeof (struct imap_cmd ));
510
- nfvasprintf ( & cmd -> cmd , fmt , ap );
496
+ cmd -> cmd = xstrvfmt ( fmt , ap );
511
497
cmd -> tag = ++ imap -> nexttag ;
512
498
513
499
if (cb )
@@ -519,27 +505,30 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
519
505
get_cmd_result (ctx , NULL );
520
506
521
507
if (!cmd -> cb .data )
522
- bufl = xsnprintf ( buf , sizeof ( buf ) , "%d %s\r\n" , cmd -> tag , cmd -> cmd );
508
+ strbuf_addf ( & buf , "%d %s\r\n" , cmd -> tag , cmd -> cmd );
523
509
else
524
- bufl = xsnprintf (buf , sizeof (buf ), "%d %s{%d%s}\r\n" ,
525
- cmd -> tag , cmd -> cmd , cmd -> cb .dlen ,
526
- CAP (LITERALPLUS ) ? "+" : "" );
510
+ strbuf_addf (& buf , "%d %s{%d%s}\r\n" , cmd -> tag , cmd -> cmd ,
511
+ cmd -> cb .dlen , CAP (LITERALPLUS ) ? "+" : "" );
512
+ if (buf .len > INT_MAX )
513
+ die ("imap command overflow!" );
527
514
528
515
if (0 < verbosity ) {
529
516
if (imap -> num_in_progress )
530
517
printf ("(%d in progress) " , imap -> num_in_progress );
531
518
if (!starts_with (cmd -> cmd , "LOGIN" ))
532
- printf (">>> %s" , buf );
519
+ printf (">>> %s" , buf . buf );
533
520
else
534
521
printf (">>> %d LOGIN <user> <pass>\n" , cmd -> tag );
535
522
}
536
- if (socket_write (& imap -> buf .sock , buf , bufl ) != bufl ) {
523
+ if (socket_write (& imap -> buf .sock , buf . buf , buf . len ) != buf . len ) {
537
524
free (cmd -> cmd );
538
525
free (cmd );
539
526
if (cb )
540
527
free (cb -> data );
528
+ strbuf_release (& buf );
541
529
return NULL ;
542
530
}
531
+ strbuf_release (& buf );
543
532
if (cmd -> cb .data ) {
544
533
if (CAP (LITERALPLUS )) {
545
534
n = socket_write (& imap -> buf .sock , cmd -> cb .data , cmd -> cb .dlen );
0 commit comments