security(polymarket-browse): validate --detail argument and show error if out of range
- Add sys import for stderr/exit - Validate --detail index before accessing array - Show error with available range instead of silent fallback to first event - Exit with code 1 if --detail is out of range
This commit is contained in:
@@ -6,6 +6,7 @@ Browse tradeable Polymarket events by game category.
|
|||||||
|
|
||||||
import html
|
import html
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import argparse
|
import argparse
|
||||||
import hashlib
|
import hashlib
|
||||||
@@ -1224,10 +1225,15 @@ def main() -> None:
|
|||||||
|
|
||||||
# Print detail for selected event if any
|
# Print detail for selected event if any
|
||||||
if result["match_events"] and args.detail > 0:
|
if result["match_events"] and args.detail > 0:
|
||||||
print("\n")
|
|
||||||
idx = args.detail - 1
|
idx = args.detail - 1
|
||||||
if idx < 0 or idx >= len(result["match_events"]):
|
num_events = len(result["match_events"])
|
||||||
idx = 0
|
if idx < 0 or idx >= num_events:
|
||||||
|
print(
|
||||||
|
f"Error: --detail {args.detail} is out of range (available: 1-{num_events}).",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
print("\n")
|
||||||
detail_event = result["match_events"][idx]
|
detail_event = result["match_events"][idx]
|
||||||
detail = format_detail_event(detail_event)
|
detail = format_detail_event(detail_event)
|
||||||
print_detail(detail_event, detail)
|
print_detail(detail_event, detail)
|
||||||
|
|||||||
Reference in New Issue
Block a user