~ecryptfs/ecryptfs/trunk

« back to all changes in this revision

Viewing changes to src/libecryptfs/module_mgr.c

  • Committer: Tyler Hicks
  • Date: 2013-10-27 21:28:05 UTC
  • Revision ID: tyhicks@canonical.com-20131027212805-vh2261aoydnj7ge7
Fix sign comparison warnings and other issues surrounding the uint32_t type
used for key_bytes

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <string.h>
24
24
#include <stdlib.h>
25
25
#include <stdio.h>
 
26
#include <stdint.h>
 
27
#include <inttypes.h>
26
28
#include "../include/ecryptfs.h"
27
29
#include "../include/decision_graph.h"
28
30
 
438
440
}
439
441
 
440
442
static int init_ecryptfs_key_bytes_param_node(char *cipher_name, 
441
 
                                              int min, int max)
 
443
                                              uint32_t min, uint32_t max)
442
444
{
443
445
        int i;
444
446
        int rc = 0;
453
455
                        
454
456
                        tn = &ecryptfs_key_bytes_param_node.tl[
455
457
                                ecryptfs_key_bytes_param_node.num_transitions];
456
 
                        rc = asprintf(&tn->val, "%d",
 
458
                        rc = asprintf(&tn->val, "%"PRIu32,
457
459
                                      supported_key_bytes[i].key_bytes);
458
460
                        if (rc == -1) {
459
461
                                rc = -ENOMEM;
462
464
                        rc = 0;
463
465
                        if (!ecryptfs_key_bytes_param_node.suggested_val) {
464
466
                                rc = asprintf(&ecryptfs_key_bytes_param_node.suggested_val,
465
 
                                              "%d",
 
467
                                              "%"PRIu32,
466
468
                                              supported_key_bytes[i].key_bytes);
467
469
                                if (rc == -1) {
468
470
                                        rc = -ENOMEM;
485
487
        return rc;
486
488
}
487
489
 
 
490
static int parse_key_bytes(uint32_t *bytes, const char *str)
 
491
{
 
492
        uintmax_t tmp;
 
493
        char *eptr;
 
494
 
 
495
        if (str[0] == '-')
 
496
                return -ERANGE;
 
497
 
 
498
        errno = 0;
 
499
        tmp = strtoumax(str, &eptr, 10);
 
500
        if (eptr == str)
 
501
                return -EINVAL;
 
502
        else if (tmp == UINT_MAX && errno == ERANGE)
 
503
                return -ERANGE;
 
504
        else if (tmp > UINT32_MAX)
 
505
                return -ERANGE;
 
506
 
 
507
        *bytes = (uint32_t)tmp;
 
508
        return 0;
 
509
}
 
510
 
488
511
static int tf_ecryptfs_cipher(struct ecryptfs_ctx *ctx, struct param_node *node,
489
512
                              struct val_node **head, void **foo)
490
513
{
491
514
        char *opt;
492
515
        int rc;
493
 
        int min = 0, max = 999999;
 
516
        uint32_t min = 0, max = 999999;
494
517
        struct val_node *tmp = *head, *tmpprev = NULL;
495
518
 
496
519
        while (tmp) {
498
521
                int popval = 0;
499
522
                if (tmp->val && (strstr(tmp->val,"max_key_bytes=") != NULL) && 
500
523
                    ((ptr=strchr(tmp->val,'=')) != NULL)) {
501
 
                        char *eptr;
502
 
                        max = strtol(++ptr, &eptr, 10);
503
 
                        if (eptr == ptr)
504
 
                                return -EINVAL;
 
524
                        rc = parse_key_bytes(&max, ++ptr);
 
525
                        if (rc)
 
526
                                return rc;
505
527
                        popval = 1;
506
528
                }
507
529
                if (tmp->val && (strstr(tmp->val,"min_key_bytes=") != NULL) && 
508
530
                    ((ptr=strchr(tmp->val,'=')) != NULL)) {
509
 
                        char *eptr;
510
 
                        min = strtol(++ptr, &eptr, 10);
511
 
                        if (eptr == ptr)
512
 
                                return -EINVAL;
 
531
                        rc = parse_key_bytes(&min, ++ptr);
 
532
                        if (rc)
 
533
                                return rc;
513
534
                        popval = 1;
514
535
                }
515
536
                if (popval) {