From f9236479f742a2065779cbd185f3e318ae696d09 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 30 Apr 2018 02:16:15 +0200 Subject: [PATCH] cli checks for qr code generation errors --- cmdline/cmdline.c | 1 + cmdline/main.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cmdline/cmdline.c b/cmdline/cmdline.c index 2df49b09..6c4d63ed 100644 --- a/cmdline/cmdline.c +++ b/cmdline/cmdline.c @@ -1224,6 +1224,7 @@ char* mrmailbox_cmdline(mrmailbox_t* mailbox, const char* cmdline) else if( strcmp(cmd, "getqr")==0 ) { ret = mrmailbox_get_securejoin_qr(mailbox, arg1? atoi(arg1) : 0); + if( ret == NULL || ret[0]==0 ) { free(ret); ret = COMMAND_FAILED; } } else if( strcmp(cmd, "checkqr")==0 ) { diff --git a/cmdline/main.c b/cmdline/main.c index 55aa044d..d38a9e34 100644 --- a/cmdline/main.c +++ b/cmdline/main.c @@ -166,13 +166,15 @@ int main(int argc, char ** argv) { mrmailbox_connect(mailbox); char* qrstr = mrmailbox_get_securejoin_qr(mailbox, arg1? atoi(arg1) : 0); - if( strcmp(cmd, "getbadqr")==0 && strlen(qrstr)>40 ) { - for( int i = 12; i < 22; i++ ) { qrstr[i] = '0'; } + if( qrstr && qrstr[0] ) { + if( strcmp(cmd, "getbadqr")==0 && strlen(qrstr)>40 ) { + for( int i = 12; i < 22; i++ ) { qrstr[i] = '0'; } + } + printf("%s\n", qrstr); + char* syscmd = mr_mprintf("qrencode -t ansiutf8 \"%s\" -o -", qrstr); /* `-t ansiutf8`=use back/write, `-t utf8`=use terminal colors */ + system(syscmd); + free(syscmd); } - printf("%s\n", qrstr); - char* syscmd = mr_mprintf("qrencode -t ansiutf8 \"%s\" -o -", qrstr); /* `-t ansiutf8`=use back/write, `-t utf8`=use terminal colors */ - system(syscmd); - free(syscmd); free(qrstr); } else if( strcmp(cmd, "exit")==0 )