aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@mines-paris.org>2018-07-27 19:29:07 +0200
committerGitHub <noreply@github.com>2018-07-27 19:29:07 +0200
commit7b7e69690d13bd5d6b6468c6a11a81f871bd7127 (patch)
tree87cb3d9f4860d66d32aa9ca3c1b966225307be2d
parent54c854abb78a16169ff4f883805050734ecaa65d (diff)
parent6be10ac6ab4e21101a913c33a30cf23901593914 (diff)
downloadPROJ-7b7e69690d13bd5d6b6468c6a11a81f871bd7127.tar.gz
PROJ-7b7e69690d13bd5d6b6468c6a11a81f871bd7127.zip
Merge pull request #1083 from schwehr/pj_strerrno-asan
pj_strerrno(): Change check of err value to avoid undefined behavior.
-rw-r--r--src/pj_strerrno.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/pj_strerrno.c b/src/pj_strerrno.c
index d37e6d5f..16042f79 100644
--- a/src/pj_strerrno.c
+++ b/src/pj_strerrno.c
@@ -74,6 +74,7 @@ pj_err_list[] = {
};
char *pj_strerrno(int err) {
+ const int max_error = 9999;
static char note[50];
size_t adjusted_err;
@@ -87,17 +88,19 @@ char *pj_strerrno(int err) {
#else
/* Defend string boundary against exorbitantly large err values */
/* which may occur on platforms with 64-bit ints */
- sprintf(note,"no system list, errno: %d\n", (err < 9999)? err: 9999);
+ sprintf(note, "no system list, errno: %d\n",
+ (err < max_error) ? err: max_error);
return note;
#endif
}
- /* PROJ.4 error codes are negative */
- adjusted_err = - err - 1;
+ /* PROJ.4 error codes are negative: -1 to -9999 */
+ adjusted_err = err < -max_error ? max_error : -err - 1;
if (adjusted_err < (sizeof(pj_err_list) / sizeof(char *)))
return (char *)pj_err_list[adjusted_err];
- sprintf( note, "invalid projection system error (%d)", (err > -9999)? err: -9999);
+ sprintf(note, "invalid projection system error (%d)",
+ (err > -max_error) ? err: -max_error);
return note;
}