Skip to content

Commit

Permalink
Handle errors from strtol
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Sep 27, 2021
1 parent 07b0c8b commit 4d79dcc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Revision history for PostgreSQL extension semver.

0.31.2
- Fix an overflow check to properly compare the max size of INT32
rather than INT. Thanks to Felix Lechner for the report (#58).
- Add an overflow check and properly compare the max size of INT32
rather than INT. Thanks to Felix Lechner for the report and Tom Lane
for the C lesson (#58).

0.31.1 2021-04-27T00:10:07Z
- Updated the C code to pass the correct number of arguments to
Expand Down
3 changes: 2 additions & 1 deletion src/semver.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ semver* parse_semver(char* str, bool lax, bool throw, bool* bad) {
atchar++;
curpart++;
} else { // OK, it should be a version part number then
errno = 0;
num = strtol(ptr, &endptr, 10);
// N.B. According to strtol(3), a valid number may be preceded
// by a single +/-, so a value like 0.1-1 will end up being
Expand All @@ -142,7 +143,7 @@ semver* parse_semver(char* str, bool lax, bool throw, bool* bad) {
elog(ERROR, "bad semver value '%s': expected number/separator at char %d", str, atchar);
}
}
if (num > INT32_MAX) { // Too big
if (errno != 0 || num > INT32_MAX) { // Invalid or too big
*bad = true;
if (!throw) break;
elog(ERROR, "bad semver value '%s': version number exceeds 31-bit range", str);
Expand Down

0 comments on commit 4d79dcc

Please sign in to comment.