Actions
Bug #9868
closedbigdecimal#VpAlloc causes out-of-bounds read
    Bug #9868:
    bigdecimal#VpAlloc causes out-of-bounds read
  
Description
以下のようなパッチを当てて
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 44e13a4..400dda0 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -3911,6 +3911,7 @@ VpAlloc(size_t mx, const char *szVal)
     }
     /* Skip trailing spaces */
     while (--i > 0) {
+       printf("dereference psz[%lu]\n", i);
        if (ISSPACE(psz[i])) psz[i] = 0;
        else break;
     }
以下のようなコードを実行すると、
$ ./ruby -I .ext/x86_64-linux/ -I . -I lib -r bigdecimal -e 'p BigDecimal.new("#")'
dereference psz[1]
dereference psz[8]
dereference psz[2]
dereference psz[18446744073709551615]
#<BigDecimal:7f06266cb820,'0.0',9(9)>
見るからにまずそうなデリファレンスが行われていることが観察されます。
Coverity Scan が見つけてくれました。
--
Yusuke Endoh mame@ruby-lang.org
        
          
          Updated by nobu (Nobuyoshi Nakada) over 11 years ago
          
          
        
        
      
      - Description updated (diff)
 
i--ですかね。
その次のISSPACE()までループの条件に入れてしまったほうがいい気がしますが。
        
          
          Updated by naruse (Yui NARUSE) almost 8 years ago
          
          
        
        
      
      - Target version deleted (
2.2.0) 
        
          
          Updated by jeremyevans0 (Jeremy Evans) about 6 years ago
          
          
        
        
      
      - Status changed from Open to Closed
 
I think this is fixed by https://github.com/ruby/bigdecimal/commit/e738c1377108baa0c2fd03cdee0eeb1239f627b2.
Actions