/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2009-02-12 18:56:52 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090212185652-ast00yprt2pe2l4p
Overflows are not detected by sscanf(), so stop using it:

* plugin-runner.c (main/parse_opt): Change from using "sscanf()" to
                                    "strtoimax()".
* plugins.d/mandos-client.c (main/parse_opt, main): Change from using
                                                    "sscanf()" to
                                                    "strtoimax()" and
                                                    "strtof()".
* splashy.c (main): Change from using "sscanf()" to "strtoimax()".
* usplash.c (main): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#define _GNU_SOURCE             /* TEMP_FAILURE_RETRY(), asprintf() */
37
37
 
38
38
#include <stdio.h>              /* fprintf(), stderr, fwrite(),
39
 
                                   stdout, ferror(), sscanf(),
40
 
                                   remove() */
 
39
                                   stdout, ferror(), remove() */
41
40
#include <stdint.h>             /* uint16_t, uint32_t */
42
41
#include <stddef.h>             /* NULL, size_t, ssize_t */
43
42
#include <stdlib.h>             /* free(), EXIT_SUCCESS, EXIT_FAILURE,
44
 
                                   srand() */
 
43
                                   srand(), strtof() */
45
44
#include <stdbool.h>            /* bool, false, true */
46
45
#include <string.h>             /* memset(), strcmp(), strlen(),
47
46
                                   strerror(), asprintf(), strcpy() */
56
55
#include <fcntl.h>              /* open() */
57
56
#include <dirent.h>             /* opendir(), struct dirent, readdir()
58
57
                                 */
59
 
#include <inttypes.h>           /* PRIu16, intmax_t, SCNdMAX */
 
58
#include <inttypes.h>           /* PRIu16, PRIdMAX, intmax_t,
 
59
                                   strtoimax() */
60
60
#include <assert.h>             /* assert() */
61
61
#include <errno.h>              /* perror(), errno */
62
62
#include <time.h>               /* nanosleep(), time() */
894
894
  int error;
895
895
  int ret;
896
896
  intmax_t tmpmax;
897
 
  int numchars;
 
897
  char *tmp;
898
898
  int exitcode = EXIT_SUCCESS;
899
899
  const char *interface = "eth0";
900
900
  struct ifreq network;
914
914
                         ":!CTYPE-X.509:+CTYPE-OPENPGP" };
915
915
  bool gnutls_initialized = false;
916
916
  bool gpgme_initialized = false;
917
 
  double delay = 2.5;
918
 
 
 
917
  float delay = 2.5f;
 
918
  
919
919
  struct sigaction old_sigterm_action;
920
920
  struct sigaction sigterm_action = { .sa_handler = handle_sigterm };
921
921
  
975
975
        pubkey = arg;
976
976
        break;
977
977
      case 129:                 /* --dh-bits */
978
 
        ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
979
 
        if(ret < 1 or tmpmax != (typeof(mc.dh_bits))tmpmax
980
 
           or arg[numchars] != '\0'){
 
978
        errno = 0;
 
979
        tmpmax = strtoimax(arg, &tmp, 10);
 
980
        if(errno != 0 or tmp == arg or *tmp != '\0'
 
981
           or tmpmax != (typeof(mc.dh_bits))tmpmax){
981
982
          fprintf(stderr, "Bad number of DH bits\n");
982
983
          exit(EXIT_FAILURE);
983
984
        }
987
988
        mc.priority = arg;
988
989
        break;
989
990
      case 131:                 /* --delay */
990
 
        ret = sscanf(arg, "%lf%n", &delay, &numchars);
991
 
        if(ret < 1 or arg[numchars] != '\0'){
 
991
        errno = 0;
 
992
        delay = strtof(arg, &tmp);
 
993
        if(errno != 0 or tmp == arg or *tmp != '\0'){
992
994
          fprintf(stderr, "Bad delay\n");
993
995
          exit(EXIT_FAILURE);
994
996
        }
1200
1202
      goto end;
1201
1203
    }
1202
1204
    uint16_t port;
1203
 
    ret = sscanf(address+1, "%" SCNdMAX "%n", &tmpmax, &numchars);
1204
 
    if(ret < 1 or tmpmax != (uint16_t)tmpmax
1205
 
       or address[numchars+1] != '\0'){
 
1205
    errno = 0;
 
1206
    tmpmax = strtoimax(address+1, &tmp, 10);
 
1207
    if(errno != 0 or tmp == address+1 or *tmp != '\0'
 
1208
       or tmpmax != (uint16_t)tmpmax){
1206
1209
      fprintf(stderr, "Bad port number\n");
1207
1210
      exitcode = EXIT_FAILURE;
1208
1211
      goto end;