/mandos/release

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

« back to all changes in this revision

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

Fixes for sscanf usage:

* plugin-runner.c (main): Parse numbers correctly and portably using
                          an intermediate "intmax_t".  Cast "pid_t" to
                          "intmax_t" before passing it to "printf()".
* plugins.d/mandos-client.c (main): Parse numbers correctly and
                                    portably using an intermediate
                                    "intmax_t".  Bug fix: cast
                                    "AvahiIfIndex" to "intmax_t" and
                                    use "PRIdMAX" instead of using
                                    "PRIu16", and use "PRIu16" to
                                    format port number.
* plugins.d/splashy.c (main): Parse numbers correctly and portably
                              using an intermediate "intmax_t".
* plugins.d/usplash.c (main): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
#include <fcntl.h>              /* open() */
58
58
#include <dirent.h>             /* opendir(), struct dirent, readdir()
59
59
                                 */
60
 
#include <inttypes.h>           /* PRIu16, SCNu16 */
 
60
#include <inttypes.h>           /* PRIu16, intmax_t, SCNdMAX */
61
61
#include <assert.h>             /* assert() */
62
62
#include <errno.h>              /* perror(), errno */
63
63
#include <time.h>               /* time() */
365
365
}
366
366
 
367
367
static const char * safer_gnutls_strerror(int value) {
368
 
  const char *ret = gnutls_strerror(value); /* Spurious warning */
 
368
  const char *ret = gnutls_strerror(value); /* Spurious warning from
 
369
                                               -Wunreachable-code */
369
370
  if(ret == NULL)
370
371
    ret = "(unknown)";
371
372
  return ret;
404
405
  /* OpenPGP credentials */
405
406
  gnutls_certificate_allocate_credentials(&mc->cred);
406
407
  if(ret != GNUTLS_E_SUCCESS){
407
 
    fprintf(stderr, "GnuTLS memory error: %s\n", /* Spurious
408
 
                                                    warning */
 
408
    fprintf(stderr, "GnuTLS memory error: %s\n", /* Spurious warning
 
409
                                                  * from
 
410
                                                  * -Wunreachable-code
 
411
                                                  */
409
412
            safer_gnutls_strerror(ret));
410
413
    gnutls_global_deinit();
411
414
    return -1;
553
556
    fprintf(stderr, "Bad address: %s\n", ip);
554
557
    return -1;
555
558
  }
556
 
  to.in6.sin6_port = htons(port); /* Spurious warning */
 
559
  to.in6.sin6_port = htons(port); /* Spurious warnings from
 
560
                                     -Wconversion and
 
561
                                     -Wunreachable-code */
557
562
  
558
563
  to.in6.sin6_scope_id = (uint32_t)if_index;
559
564
  
749
754
      avahi_address_snprint(ip, sizeof(ip), address);
750
755
      if(debug){
751
756
        fprintf(stderr, "Mandos server \"%s\" found on %s (%s, %"
752
 
                PRIu16 ") on port %d\n", name, host_name, ip,
753
 
                interface, port);
 
757
                PRIdMAX ") on port %" PRIu16 "\n", name, host_name,
 
758
                ip, (intmax_t)interface, port);
754
759
      }
755
760
      int ret = start_mandos_communication(ip, port, interface, mc);
756
761
      if(ret == 0){
816
821
    AvahiSServiceBrowser *sb = NULL;
817
822
    int error;
818
823
    int ret;
 
824
    intmax_t tmpmax;
 
825
    int numchars;
819
826
    int exitcode = EXIT_SUCCESS;
820
827
    const char *interface = "eth0";
821
828
    struct ifreq network;
886
893
          pubkey = arg;
887
894
          break;
888
895
        case 129:               /* --dh-bits */
889
 
          ret = sscanf(arg, "%u", &mc.dh_bits);
890
 
          if(ret != 1){
 
896
          ret = sscanf(arg, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
897
          if(ret < 1 or tmpmax != (typeof(mc.dh_bits))tmpmax
 
898
             or arg[numchars] != '\0'){
891
899
            fprintf(stderr, "Bad number of DH bits\n");
892
900
            exit(EXIT_FAILURE);
893
901
          }
 
902
          mc.dh_bits = (typeof(mc.dh_bits))tmpmax;
894
903
          break;
895
904
        case 130:               /* --priority */
896
905
          mc.priority = arg;
999
1008
        goto end;
1000
1009
      }
1001
1010
      uint16_t port;
1002
 
      ret = sscanf(address+1, "%" SCNu16, &port);
1003
 
      if(ret != 1){
 
1011
      ret = sscanf(address+1, "%" SCNdMAX "%n", &tmpmax, &numchars);
 
1012
      if(ret < 1 or tmpmax != (uint16_t)tmpmax
 
1013
         or address[numchars+1] != '\0'){
1004
1014
        fprintf(stderr, "Bad port number\n");
1005
1015
        exitcode = EXIT_FAILURE;
1006
1016
        goto end;
1007
1017
      }
 
1018
      port = (uint16_t)tmpmax;
1008
1019
      *address = '\0';
1009
1020
      address = connect_to;
1010
1021
      ret = start_mandos_communication(address, port, if_index, &mc);