1. 01 Jun, 2020 3 commits
    • philmd's avatar
      Remove unnecessary break · d877d74b
      philmd authored
      The code is unreachable, so no need to break.
      This silence static analyzer warnings.
      Signed-off-by: philmd's avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: Samuel Thibault's avatarSamuel Thibault <samuel.thibault@ens-lyon.org>
      d877d74b
    • philmd's avatar
      Fix constness warnings · 6826a991
      philmd authored
      Fix the following GCC warnings:
      
        src/ncsi.c: In function ‘ncsi_input’:
        src/ncsi.c:139:31: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual]
          139 |     struct ncsi_pkt_hdr *nh = (struct ncsi_pkt_hdr *)(pkt + ETH_HLEN);
              |                               ^
        src/dnssearch.c: In function ‘translate_dnssearch’:
        src/dnssearch.c:242:33: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual]
          242 |     num_domains = g_strv_length((GStrv)names);
              |                                 ^
        src/slirp.c: In function ‘arp_input’:
        src/slirp.c:747:31: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual]
          747 |     struct slirp_arphdr *ah = (struct slirp_arphdr *)(pkt + ETH_HLEN);
              |                               ^
        src/dnssearch.c: In function ‘translate_dnssearch’:
        src/dnssearch.c:242:33: error: cast discards ‘const’ qualifier from pointer target type [-Werror=cast-qual]
          242 |     num_domains = g_strv_length((const GStrv)names);
              |                                 ^
        src/slirp.c: In function ‘arp_input’:
        src/slirp.c:764:48: error: passing argument 3 of ‘arp_table_add’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
          764 |             arp_table_add(slirp, ah->ar_sip, ah->ar_sha);
              |                                              ~~^~~~~~~~
        In file included from src/slirp.c:25:
        src/slirp.h:101:60: note: expected ‘uint8_t *’ {aka ‘unsigned char *’} but argument is of type ‘const unsigned char *’
          101 | void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
              |                                                    ~~~~~~~~^~~~~~~~~~~~~~~~~
        src/slirp.c:783:48: error: passing argument 3 of ‘arp_table_add’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
          783 |             arp_table_add(slirp, ah->ar_sip, ah->ar_sha);
              |                                              ~~^~~~~~~~
        In file included from src/slirp.c:25:
        src/slirp.h:101:60: note: expected ‘uint8_t *’ {aka ‘unsigned char *’} but argument is of type ‘const unsigned char *’
          101 | void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
              |                                                    ~~~~~~~~^~~~~~~~~~~~~~~~~
        src/slirp.c:804:44: error: passing argument 3 of ‘arp_table_add’ discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
          804 |         arp_table_add(slirp, ah->ar_sip, ah->ar_sha);
              |                                          ~~^~~~~~~~
        In file included from src/slirp.c:25:
        src/slirp.h:101:60: note: expected ‘uint8_t *’ {aka ‘unsigned char *’} but argument is of type ‘const unsigned char *’
          101 | void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
              |                                                    ~~~~~~~~^~~~~~~~~~~~~~~~~
      Signed-off-by: philmd's avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: Samuel Thibault's avatarSamuel Thibault <samuel.thibault@ens-lyon.org>
      6826a991
    • philmd's avatar
      Fix win32 builds by using the SLIRP_PACKED definition · bcaaa53a
      philmd authored
      A packed struct needs different gcc attributes for compilations
      with MinGW compilers because glib-2.0 adds compiler flag
      -mms-bitfields which modifies the packing algorithm.
      
      Attribute gcc_struct reverses the negative effects of -mms-bitfields.
      
      We already have the SLIRP_PACKED definition for that, use it.
      Signed-off-by: philmd's avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: Samuel Thibault's avatarSamuel Thibault <samuel.thibault@ens-lyon.org>
      bcaaa53a
  2. 27 May, 2020 4 commits
    • Jindrich Novy's avatar
      Check lseek() for failure · 961a676e
      Jindrich Novy authored
      Error: CHECKED_RETURN (CWE-252): [#def26]
      libslirp-4.3.0/src/tftp.c:121: check_return: Calling "lseek(spt->fd, block_nr * spt->block_size, 0)" without checking return value. This library function may fail and return an error code.
        119|
        120|       if (len) {
        121|->         lseek(spt->fd, block_nr * spt->block_size, SEEK_SET);
        122|
        123|           bytes_read = read(spt->fd, buf, len);
      Signed-off-by: Jindrich Novy's avatarJindrich Novy <jnovy@redhat.com>
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      961a676e
    • Jindrich Novy's avatar
      Be sure to initialize sockaddr structure · b0fc01a6
      Jindrich Novy authored
      Error: UNINIT (CWE-457): [#def30]
      libslirp-4.3.0/src/udp.c:325: var_decl: Declaring variable "addr" without initializer.
      libslirp-4.3.0/src/udp.c:342: uninit_use_in_call: Using uninitialized value "addr". Field "addr.sin_zero" is uninitialized when calling "bind".
      Signed-off-by: Jindrich Novy's avatarJindrich Novy <jnovy@redhat.com>
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      b0fc01a6
    • Jindrich Novy's avatar
      Use secure string copy to avoid overflow · 2d79c0b7
      Jindrich Novy authored
      Error: STRING_OVERFLOW (CWE-120): [#def2]
      libslirp-4.3.0/src/ip_icmp.c:277: fixed_size_dest: You might overrun the 20-character fixed-size string "bufa" by copying the return value of "inet_ntoa" without checking the length.
        275|       if (slirp_debug & DBG_MISC) {
        276|           char bufa[20], bufb[20];
        277|->         strcpy(bufa, inet_ntoa(ip->ip_src));
        278|           strcpy(bufb, inet_ntoa(ip->ip_dst));
        279|           DEBUG_MISC(" %.16s to %.16s", bufa, bufb);
      
      Error: STRING_OVERFLOW (CWE-120): [#def3]
      libslirp-4.3.0/src/ip_icmp.c:278: fixed_size_dest: You might overrun the 20-character fixed-size string "bufb" by copying the return value of "inet_ntoa" without checking the length.
        276|           char bufa[20], bufb[20];
        277|           strcpy(bufa, inet_ntoa(ip->ip_src));
        278|->         strcpy(bufb, inet_ntoa(ip->ip_dst));
        279|           DEBUG_MISC(" %.16s to %.16s", bufa, bufb);
        280|       }
      Signed-off-by: Jindrich Novy's avatarJindrich Novy <jnovy@redhat.com>
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      2d79c0b7
    • Jindrich Novy's avatar
      Fix possible infinite loops and use-after-free · 0b83636e
      Jindrich Novy authored
      Error: USE_AFTER_FREE (CWE-416): [#def1]
      libslirp-4.3.0/src/ip_icmp.c:79: freed_arg: "icmp_detach" frees "slirp->icmp.so_next".
      libslirp-4.3.0/src/ip_icmp.c:79: deref_arg: Calling "icmp_detach" dereferences freed pointer "slirp->icmp.so_next".
         77|   {
         78|       while (slirp->icmp.so_next != &slirp->icmp) {
         79|->         icmp_detach(slirp->icmp.so_next);
         80|       }
         81|   }
      
      Error: USE_AFTER_FREE (CWE-416): [#def27]
      libslirp-4.3.0/src/udp.c:56: freed_arg: "udp_detach" frees "slirp->udb.so_next".
      libslirp-4.3.0/src/udp.c:56: deref_arg: Calling "udp_detach" dereferences freed pointer "slirp->udb.so_next".
         54|   {
         55|       while (slirp->udb.so_next != &slirp->udb) {
         56|->         udp_detach(slirp->udb.so_next);
         57|       }
         58|   }
      Signed-off-by: Jindrich Novy's avatarJindrich Novy <jnovy@redhat.com>
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      0b83636e
  3. 23 Apr, 2020 2 commits
  4. 22 Apr, 2020 1 commit
  5. 20 Apr, 2020 2 commits
  6. 06 Apr, 2020 1 commit
  7. 25 Mar, 2020 1 commit
  8. 24 Mar, 2020 3 commits
  9. 23 Mar, 2020 1 commit
  10. 21 Mar, 2020 1 commit
  11. 20 Mar, 2020 2 commits
  12. 18 Mar, 2020 1 commit
  13. 17 Mar, 2020 9 commits
  14. 16 Mar, 2020 6 commits
  15. 02 Mar, 2020 2 commits
  16. 03 Feb, 2020 1 commit