Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d8dc5b3f authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

screencap: Fix parsing of display IDs

The underlying type of DisplayId is uint64_t, but screencap parsed the
IDs as signed 64-bit, invoking undefined behavior for out-of-range IDs.
In practice, out-of-range IDs were clamped, so SF failed to find them.

Fixes: 302580952
Test: screencap works for virtual display on Felix
Change-Id: I09a863d0c68dbb857b6f756b51159e5e3d853f5d
parent fa76ad2f
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -142,13 +142,22 @@ int main(int argc, char** argv)
            case 'p':
                png = true;
                break;
            case 'd':
                displayIdOpt = DisplayId::fromValue(atoll(optarg));
            case 'd': {
                errno = 0;
                char* end = nullptr;
                const uint64_t id = strtoull(optarg, &end, 10);
                if (!end || *end != '\0' || errno == ERANGE) {
                    fprintf(stderr, "Invalid display ID: Out of range [0, 2^64).\n");
                    return 1;
                }

                displayIdOpt = DisplayId::fromValue(id);
                if (!displayIdOpt) {
                    fprintf(stderr, "Invalid display ID: %s\n", optarg);
                    fprintf(stderr, "Invalid display ID: Incorrect encoding.\n");
                    return 1;
                }
                break;
            }
            case '?':
            case 'h':
                if (ids.size() == 1) {