Changeset 617

Show
Ignore:
Timestamp:
09/05/08 16:40:36
Author:
rachel
Message:

More changes for Coverity

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openpgpsdk/trunk/include/openpgpsdk/create.h

    r574 r617  
    4747void ops_create_info_delete(ops_create_info_t *info); 
    4848 
    49 ops_memory_t* ops_write_buf_from_file(const char *filename); 
     49ops_memory_t* ops_write_buf_from_file(const char *filename, int* errnum); 
    5050int ops_write_file_from_buf(const char *filename, const char* buf, const size_t len, const ops_boolean_t overwrite); 
    5151 
  • openpgpsdk/trunk/include/openpgpsdk/errors.h

    r610 r617  
    6969    OPS_E_V_NO_SIGNATURE        =OPS_E_V+2, 
    7070    OPS_E_V_UNKNOWN_SIGNER      =OPS_E_V+3, 
     71    OPS_E_V_BAD_HASH            =OPS_E_V+4, 
    7172 
    7273    /* Algorithm support errors */ 
  • openpgpsdk/trunk/include/openpgpsdk/signature.h

    r573 r617  
    9090ops_boolean_t ops_sign_file_as_cleartext(const char* filename, const ops_secret_key_t *skey, const ops_boolean_t overwrite); 
    9191ops_boolean_t ops_sign_buf_as_cleartext(const char* input, const size_t len, ops_memory_t** output, const ops_secret_key_t *skey); 
    92 void ops_sign_file(const char* input_filename, const char* output_filename, const ops_secret_key_t *skey, const ops_boolean_t use_armour, const ops_boolean_t overwrite); 
     92ops_boolean_t ops_sign_file(const char* input_filename, const char* output_filename, const ops_secret_key_t *skey, const ops_boolean_t use_armour, const ops_boolean_t overwrite); 
    9393ops_memory_t * ops_sign_mem(const void* input, const int input_len, const ops_sig_type_t sig_type,  const ops_secret_key_t *skey, const ops_boolean_t use_armour); 
    9494 
  • openpgpsdk/trunk/src/app/openpgp.c

    r616 r617  
    4141#define DEFAULT_NUMBITS 1024 
    4242 
     43#define MAXBUF 1024 
     44 
    4345static const char* usage="%s --list-keys | --encrypt | --decrypt | --sign | --clearsign | --verify [--keyring=<keyring>] [--userid=<userid>] [--filename=<filename>] [--armour] [--homedir=<homedir>]\n"; 
    4446static const char* usage_list_keys="%s --list-keys [--keyring=<keyring>]\n"; 
     
    126128 
    127129    pname=argv[0]; 
    128     const int maxbuf=1024; 
    129     char opt_keyring[maxbuf+1]; 
    130     char opt_userid[maxbuf+1]; 
    131     char opt_passphrase[maxbuf+1]; 
    132     char opt_filename[maxbuf+1]; 
    133     char opt_homedir[maxbuf+1]; 
    134     //    char opt_numbits[maxbuf+1]; 
     130    char opt_keyring[MAXBUF+1]=""; 
     131    char opt_userid[MAXBUF+1]=""; 
     132    char opt_passphrase[MAXBUF+1]=""; 
     133    char opt_filename[MAXBUF+1]=""; 
     134    char opt_homedir[MAXBUF+1]=""; 
     135 
    135136    int got_homedir=0; 
    136137    int got_keyring=0; 
     
    140141    int got_numbits=0; 
    141142    int numbits=DEFAULT_NUMBITS; 
    142     char outputfilename[maxbuf+1]
     143    char outputfilename[MAXBUF+1]=""
    143144    ops_keyring_t* myring=NULL; 
    144     char myring_name[maxbuf+1]
     145    char myring_name[MAXBUF+1]=""
    145146    ops_keyring_t* pubring=NULL; 
    146     char pubring_name[maxbuf+1]
     147    char pubring_name[MAXBUF+1]=""
    147148    ops_keyring_t* secring=NULL; 
    148     char secring_name[maxbuf+1]
     149    char secring_name[MAXBUF+1]=""
    149150    const ops_keydata_t* keydata=NULL; 
    150151    char *suffix=NULL; 
    151152    char *dir=NULL; 
    152     char default_homedir[maxbuf+1]; 
    153     //    char full_keyringname[maxbuf+1]; 
     153    char default_homedir[MAXBUF+1]=""; 
    154154    ops_boolean_t overwrite=ops_true; 
    155155    ops_keydata_t* mykeydata=NULL; 
     
    158158    ops_validate_result_t *validate_result=NULL; 
    159159    ops_user_id_t uid; 
    160     //char line[maxbuf+1]; 
    161     //int i=0; 
    162160    ops_secret_key_t* skey=NULL; 
    163161 
    164  
    165     memset(opt_keyring,'\0',sizeof(opt_keyring)); 
    166     memset(opt_userid,'\0',sizeof(opt_userid)); 
    167     memset(opt_passphrase,'\0',sizeof(opt_passphrase)); 
    168     memset(opt_filename,'\0',sizeof(opt_filename)); 
    169     memset(opt_homedir,'\0',sizeof(opt_homedir)); 
    170  
    171     memset(outputfilename,'\0',sizeof(outputfilename)); 
    172162 
    173163    if (argc<2) 
     
    243233        case KEYRING: 
    244234            assert(optarg); 
    245             snprintf(opt_keyring,maxbuf,"%s",optarg); 
     235            snprintf(opt_keyring,MAXBUF,"%s",optarg); 
    246236            got_keyring=1; 
    247237            break; 
     
    249239        case USERID: 
    250240            assert(optarg); 
    251             snprintf(opt_userid,maxbuf,"%s",optarg); 
     241            snprintf(opt_userid,MAXBUF,"%s",optarg); 
    252242            got_userid=1; 
    253243            break; 
     
    255245        case PASSPHRASE: 
    256246            assert(optarg); 
    257             snprintf(opt_passphrase,maxbuf,"%s",optarg); 
     247            snprintf(opt_passphrase,MAXBUF,"%s",optarg); 
    258248            got_passphrase=1; 
    259249            break; 
     
    261251        case FILENAME: 
    262252            assert(optarg); 
    263             snprintf(opt_filename,maxbuf,"%s",optarg); 
     253            snprintf(opt_filename,MAXBUF,"%s",optarg); 
    264254            got_filename=1; 
    265255            break; 
     
    271261        case HOMEDIR: 
    272262            assert(optarg); 
    273             snprintf(opt_homedir, maxbuf, "%s", optarg); 
     263            snprintf(opt_homedir, MAXBUF, "%s", optarg); 
    274264            got_homedir=1; 
    275265            break; 
     
    278268        case NUMBITS: 
    279269            assert(optarg); 
    280             sscanf(optarg, "%d", &numbits); 
     270            numbits=atoi(optarg); 
    281271            got_numbits=1; 
    282272            break; 
     
    301291    else 
    302292        { 
    303         snprintf(default_homedir,maxbuf,"%s/.gnupg",getenv("HOME")); 
     293        snprintf(default_homedir,MAXBUF,"%s/.gnupg",getenv("HOME")); 
    304294        printf("dir: %s\n", default_homedir); 
    305295        dir=default_homedir; 
    306296        } 
    307297 
    308     snprintf(pubring_name, maxbuf, "%s/pubring.gpg", dir); 
     298    snprintf(pubring_name, MAXBUF, "%s/pubring.gpg", dir); 
    309299    pubring=ops_mallocz(sizeof *pubring); 
    310300    if (!ops_keyring_read_from_file(pubring,ops_false,pubring_name)) 
     
    313303        exit(-1); 
    314304        } 
    315     snprintf(secring_name, maxbuf, "%s/secring.gpg", dir); 
     305    snprintf(secring_name, MAXBUF, "%s/secring.gpg", dir); 
    316306    secring=ops_mallocz(sizeof *secring); 
    317307    if (!ops_keyring_read_from_file(secring,ops_false,secring_name)) 
     
    323313    if (got_keyring) 
    324314        { 
    325         snprintf(myring_name, maxbuf, "%s/%s", opt_homedir, opt_keyring); 
     315        snprintf(myring_name, MAXBUF, "%s/%s", opt_homedir, opt_keyring); 
    326316        myring=ops_mallocz(sizeof *myring); 
    327317        if (!ops_keyring_read_from_file(myring,ops_false,myring_name)) 
     
    485475 
    486476        // outputfilename 
    487         snprintf(outputfilename,maxbuf,"%s%s", opt_filename,suffix); 
     477        snprintf(outputfilename,MAXBUF,"%s%s", opt_filename,suffix); 
    488478 
    489479        overwrite=ops_true; 
  • openpgpsdk/trunk/src/lib/create.c

    r616 r617  
    10471047    } 
    10481048 
    1049 ops_memory_t* ops_write_buf_from_file(const char *filename) 
     1049/** 
     1050   \ingroup HighLevelAPI 
     1051    
     1052   \return allocated memory. If there was an error opening the file or reading from it, errnum is set to the cause 
     1053*/ 
     1054 
     1055ops_memory_t* ops_write_buf_from_file(const char *filename, int* errnum) 
    10501056    { 
    10511057    size_t initial_size=1024; 
     
    10531059    unsigned char buf[1024]; 
    10541060    ops_memory_t* mem=NULL; 
     1061 
     1062    *errnum=0; 
    10551063 
    10561064#ifdef WIN32 
     
    10601068#endif 
    10611069    if (fd < 0) 
     1070        { 
     1071        *errnum=errno; 
    10621072        return ops_false; 
     1073        } 
    10631074 
    10641075    mem=ops_memory_new(); 
     
    10681079        ssize_t n=0; 
    10691080        n=read(fd,buf,1024); 
     1081        if (n<0) 
     1082            { 
     1083            *errnum=errno; 
     1084            break; 
     1085            } 
    10701086        if (!n) 
    10711087            break; 
  • openpgpsdk/trunk/src/lib/packet-parse.c

    r616 r617  
    24822482    if(decrypt) 
    24832483        { 
    2484         unsigned char buf[OPS_MAX_BLOCK_SIZE+2]
     2484        unsigned char buf[OPS_MAX_BLOCK_SIZE+2]=""
    24852485        size_t b=decrypt->blocksize; 
    24862486        //      ops_parser_content_t content; 
  • openpgpsdk/trunk/src/lib/reader_encrypted_seip.c

    r616 r617  
    149149                    buf[b-2],buf[b-1],buf[b],buf[b+1]); 
    150150            OPS_ERROR(errors, OPS_E_PROTO_BAD_SYMMETRIC_DECRYPT,"Bad symmetric decrypt when parsing SE IP packet"); 
     151            free(buf); 
    151152            return -1; 
    152153            } 
     
    185186        if (memcmp(mdc_hash,hashed,OPS_SHA1_HASH_SIZE)) 
    186187            { 
    187             fprintf(stderr,"Hash is bad\n"); 
    188             //            ERRP(pinfo,"Bad hash in MDC"); 
     188            OPS_ERROR(errors, OPS_E_V_BAD_HASH, "Bad hash in MDC packet"); 
     189            free(buf); 
    189190            return 0; 
    190191            } 
  • openpgpsdk/trunk/src/lib/signature.c

    r616 r617  
    921921    } 
    922922 
    923 void ops_sign_file(const char* input_filename, const char* output_filename, const ops_secret_key_t *skey, const ops_boolean_t use_armour, const ops_boolean_t overwrite) 
     923ops_boolean_t ops_sign_file(const char* input_filename, const char* output_filename, const ops_secret_key_t *skey, const ops_boolean_t use_armour, const ops_boolean_t overwrite) 
    924924    { 
    925925    // \todo allow choice of hash algorithams 
     
    941941    // read input file into buf 
    942942 
    943     mem_buf=ops_write_buf_from_file(input_filename); 
     943    int errnum; 
     944    mem_buf=ops_write_buf_from_file(input_filename,&errnum); 
     945    if (errnum) 
     946        return ops_false; 
    944947 
    945948    // setup output filename 
     
    10071010    ops_create_signature_delete(sig); 
    10081011    ops_memory_free(mem_buf); 
     1012 
     1013    return ops_true; 
    10091014    } 
    10101015 
  • openpgpsdk/trunk/tests/test_rsa_signature.c

    r574 r617  
    185185    ops_memory_t *output=NULL; 
    186186    ops_boolean_t overwrite; 
     187    int errnum=0; 
    187188 
    188189    // setup filenames  
     
    194195 
    195196    // read file contents 
    196     input=ops_write_buf_from_file(myfile); 
     197    input=ops_write_buf_from_file(myfile,&errnum); 
     198    CU_ASSERT(errnum==0); 
    197199 
    198200    // sign file