Integer Overflow or Wraparound
The product performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value.
An integer overflow occurs when an arithmetic operation attempts to create a numeric value that is outside of the range that can be represented with a given number of bits. This can lead to buffer overflows, incorrect financial calculations, or security bypasses.
この脆弱性の修正方法
3 件の Shoulder 検出ルールに基づく Integer Overflow の予防策。
Validate bounds before arithmetic operations with user-controlled integers
func handler(w http.ResponseWriter, r *http.Request) { - count, _ := strconv.Atoi(r.URL.Query().Get("count")) + count, err := strconv.Atoi(r.URL.Query().Get("count")) + if err != nil || count < 0 || count > 10000 { + http.Error(w, "Invalid count", 400) + return + } buffer := make([]byte, count*1024) }
Validate numeric bounds before using user input in allocations or arithmetic
- const size = parseInt(req.query.size, 10); + const MAX_SIZE = 1024 * 1024; + const size = parseInt(req.query.size, 10); + if (isNaN(size) || size < 0 || size > MAX_SIZE) { + return res.status(400).json({ error: 'Invalid size' }); + } const buffer = Buffer.alloc(size);
Validate numeric bounds before arithmetic operations on user input
- from flask import request - - @app.route('/calculate') - def calculate(): - count = int(request.args.get('count')) - total = count * unit_price - return {'total': total} + from flask import request, jsonify + + @app.route('/calculate') + def calculate(): + count = int(request.args.get('count', 0)) + if count < 0 or count > 10000: + return jsonify({'error': 'Invalid count'}), 400 + total = count * unit_price + return jsonify({'total': total})
コードの脆弱性を見つける
Shoulderを使用してコードのInteger Overflow or Wraparoundパターンをスキャンしましょう。 3 ルール.
# Scan with Shoulder CLI npx @shoulderdev/cli trust --cwe=190 # Or scan entire project npx @shoulderdev/cli trust .
検出ルール (3)
コードレビューで注目すべき点
これらのパターンはInteger Overflow or Wraparoundの潜在的な脆弱性を示しています。コードレビューとセキュリティ監査中に探してください。
コードベースをスキャン: Integer Overflow or Wraparound
Shoulder CLI はコードベース全体から脆弱なパターンを見つけます。