Skip to content

Commit 4d79dcc

Browse files
committed
Handle errors from strtol
1 parent 07b0c8b commit 4d79dcc

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Changes

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
Revision history for PostgreSQL extension semver.
22

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

78
0.31.1 2021-04-27T00:10:07Z
89
- Updated the C code to pass the correct number of arguments to

src/semver.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ semver* parse_semver(char* str, bool lax, bool throw, bool* bad) {
123123
atchar++;
124124
curpart++;
125125
} else { // OK, it should be a version part number then
126+
errno = 0;
126127
num = strtol(ptr, &endptr, 10);
127128
// N.B. According to strtol(3), a valid number may be preceded
128129
// by a single +/-, so a value like 0.1-1 will end up being
@@ -142,7 +143,7 @@ semver* parse_semver(char* str, bool lax, bool throw, bool* bad) {
142143
elog(ERROR, "bad semver value '%s': expected number/separator at char %d", str, atchar);
143144
}
144145
}
145-
if (num > INT32_MAX) { // Too big
146+
if (errno != 0 || num > INT32_MAX) { // Invalid or too big
146147
*bad = true;
147148
if (!throw) break;
148149
elog(ERROR, "bad semver value '%s': version number exceeds 31-bit range", str);

0 commit comments

Comments
 (0)