Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. bug of the day: a memcmp that only compares every fourth byte

bug of the day: a memcmp that only compares every fourth byte

Scheduled Pinned Locked Moved Uncategorized
25 Posts 10 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • gsuberland@chaos.socialG gsuberland@chaos.social

    @dysfun essentially this:

    int memcmp32(uint32_t* a, uint32_t* b, int words)
    {
    uint8_t sum = 0; // whoops
    while(words--) {
    sum |= *a++ ^ *b++;
    }
    return sum;
    }

    astraleureka@social.treehouse.systemsA This user is from outside of this forum
    astraleureka@social.treehouse.systemsA This user is from outside of this forum
    astraleureka@social.treehouse.systems
    wrote last edited by
    #11

    @gsuberland @dysfun lmao

    1 Reply Last reply
    0
    • gsuberland@chaos.socialG gsuberland@chaos.social

      bug of the day: a memcmp that only compares every fourth byte

      jannem@fosstodon.orgJ This user is from outside of this forum
      jannem@fosstodon.orgJ This user is from outside of this forum
      jannem@fosstodon.org
      wrote last edited by
      #12

      @gsuberland
      It's not named allmemcmp for a reason.

      1 Reply Last reply
      0
      • dysfun@social.treehouse.systemsD dysfun@social.treehouse.systems

        @gsuberland yes, that's exactly what i thought

        gsuberland@chaos.socialG This user is from outside of this forum
        gsuberland@chaos.socialG This user is from outside of this forum
        gsuberland@chaos.social
        wrote last edited by
        #13

        @dysfun ehehehe

        the code in question lucked out by never actually using it in a path that matters, but it's in a core lib for something security sensitive so easily could've ended up being bad

        dysfun@social.treehouse.systemsD 1 Reply Last reply
        0
        • gsuberland@chaos.socialG gsuberland@chaos.social

          @dysfun ehehehe

          the code in question lucked out by never actually using it in a path that matters, but it's in a core lib for something security sensitive so easily could've ended up being bad

          dysfun@social.treehouse.systemsD This user is from outside of this forum
          dysfun@social.treehouse.systemsD This user is from outside of this forum
          dysfun@social.treehouse.systems
          wrote last edited by
          #14

          @gsuberland yeah it lucked out by not having bit rotted yet

          1 Reply Last reply
          0
          • marzhall@app.wafrn.netM marzhall@app.wafrn.net

            @dysfun@social.treehouse.systems @gsuberland@chaos.social

            Hmm… is the issue casting 64-bit memory to an 8-bit char?

            gsuberland@chaos.socialG This user is from outside of this forum
            gsuberland@chaos.socialG This user is from outside of this forum
            gsuberland@chaos.social
            wrote last edited by
            #15

            @marzhall @dysfun 32-bit, but yes

            1 Reply Last reply
            0
            • gsuberland@chaos.socialG gsuberland@chaos.social

              bug of the day: a memcmp that only compares every fourth byte

              gsuberland@chaos.socialG This user is from outside of this forum
              gsuberland@chaos.socialG This user is from outside of this forum
              gsuberland@chaos.social
              wrote last edited by
              #16

              i blogged about the memcmp thing

              Watch out for missed warnings on vendor C++ toolchains - Graham Sutherland's Blog

              favicon

              (blog.poly.nomial.co.uk)

              mildsunrise@tech.lgbtM reverseics@infosec.exchangeR 2 Replies Last reply
              1
              0
              • gsuberland@chaos.socialG gsuberland@chaos.social

                i blogged about the memcmp thing

                Watch out for missed warnings on vendor C++ toolchains - Graham Sutherland's Blog

                favicon

                (blog.poly.nomial.co.uk)

                mildsunrise@tech.lgbtM This user is from outside of this forum
                mildsunrise@tech.lgbtM This user is from outside of this forum
                mildsunrise@tech.lgbt
                wrote last edited by
                #17

                @gsuberland unrelated but shouldn't it be something like *(a++) ^ *(b++)?

                gsuberland@chaos.socialG 1 Reply Last reply
                0
                • mildsunrise@tech.lgbtM mildsunrise@tech.lgbt

                  @gsuberland unrelated but shouldn't it be something like *(a++) ^ *(b++)?

                  gsuberland@chaos.socialG This user is from outside of this forum
                  gsuberland@chaos.socialG This user is from outside of this forum
                  gsuberland@chaos.social
                  wrote last edited by
                  #18

                  @mildsunrise probably yeah I'm tired lol

                  gsuberland@chaos.socialG 1 Reply Last reply
                  0
                  • gsuberland@chaos.socialG gsuberland@chaos.social

                    @mildsunrise probably yeah I'm tired lol

                    gsuberland@chaos.socialG This user is from outside of this forum
                    gsuberland@chaos.socialG This user is from outside of this forum
                    gsuberland@chaos.social
                    wrote last edited by
                    #19

                    @mildsunrise wait no, cos (a++) would be equivalent to pre-increment

                    gsuberland@chaos.socialG mildsunrise@tech.lgbtM 2 Replies Last reply
                    0
                    • gsuberland@chaos.socialG gsuberland@chaos.social

                      @mildsunrise wait no, cos (a++) would be equivalent to pre-increment

                      gsuberland@chaos.socialG This user is from outside of this forum
                      gsuberland@chaos.socialG This user is from outside of this forum
                      gsuberland@chaos.social
                      wrote last edited by
                      #20

                      @mildsunrise but yeah it should be *a ^ *b and then separately incrementing

                      1 Reply Last reply
                      0
                      • R relay@relay.infosec.exchange shared this topic
                      • gsuberland@chaos.socialG gsuberland@chaos.social

                        @mildsunrise wait no, cos (a++) would be equivalent to pre-increment

                        mildsunrise@tech.lgbtM This user is from outside of this forum
                        mildsunrise@tech.lgbtM This user is from outside of this forum
                        mildsunrise@tech.lgbt
                        wrote last edited by
                        #21

                        @gsuberland (a++) is post increment, pre increment would be (++a)

                        gsuberland@chaos.socialG 1 Reply Last reply
                        0
                        • mildsunrise@tech.lgbtM mildsunrise@tech.lgbt

                          @gsuberland (a++) is post increment, pre increment would be (++a)

                          gsuberland@chaos.socialG This user is from outside of this forum
                          gsuberland@chaos.socialG This user is from outside of this forum
                          gsuberland@chaos.social
                          wrote last edited by
                          #22

                          @mildsunrise if you wrap it in brackets and deref outside doesn't it turn into pre behaviour regardless? (now I'm writing this I'm realising it probably doesn't, but this is c++ so principle of most surprise applies lol)

                          gsuberland@chaos.socialG 1 Reply Last reply
                          0
                          • gsuberland@chaos.socialG gsuberland@chaos.social

                            @mildsunrise if you wrap it in brackets and deref outside doesn't it turn into pre behaviour regardless? (now I'm writing this I'm realising it probably doesn't, but this is c++ so principle of most surprise applies lol)

                            gsuberland@chaos.socialG This user is from outside of this forum
                            gsuberland@chaos.socialG This user is from outside of this forum
                            gsuberland@chaos.social
                            wrote last edited by
                            #23

                            @mildsunrise yeah nah I'm just tiiired

                            mildsunrise@tech.lgbtM 1 Reply Last reply
                            0
                            • gsuberland@chaos.socialG gsuberland@chaos.social

                              @mildsunrise yeah nah I'm just tiiired

                              mildsunrise@tech.lgbtM This user is from outside of this forum
                              mildsunrise@tech.lgbtM This user is from outside of this forum
                              mildsunrise@tech.lgbt
                              wrote last edited by
                              #24

                              @gsuberland dw, relatable

                              1 Reply Last reply
                              0
                              • gsuberland@chaos.socialG gsuberland@chaos.social

                                i blogged about the memcmp thing

                                Watch out for missed warnings on vendor C++ toolchains - Graham Sutherland's Blog

                                favicon

                                (blog.poly.nomial.co.uk)

                                reverseics@infosec.exchangeR This user is from outside of this forum
                                reverseics@infosec.exchangeR This user is from outside of this forum
                                reverseics@infosec.exchange
                                wrote last edited by
                                #25

                                @gsuberland i'm reminded of a weird bug i found in a compiler. in this case the vendor (green hills c compiler for coldfire cpus) converted a sequence like this:

                                ```uint8_t idx;
                                idx = ;
                                char newbyte = lookup_table[idx];

                                The code was converting upper/lowercase letters iirc.

                                In this case the compiler actually converted idx to a signed value using a coldfire MVS.B instruction for some reason, so you could obtain values outside of the lookup table array if the user input a byte >= 0x80.

                                Not incredibly useful on its own in the app I was analyzing, but the bug was in the compiler itself so needed to be fixed...I never would have spotted the bug were it not for using Ida back in the day.
                                1 Reply Last reply
                                1
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups