lib/gis: Fix security vulnerabilities and reliability bugs in core modules#7596
lib/gis: Fix security vulnerabilities and reliability bugs in core modules#7596NeelGhoshal wants to merge 10 commits into
Conversation
…x, while it holds only 3 'char *' elements
…x, while it holds only 3 'char *' elements
…me" by a call to "ctime_r"
…pwuid" by a call to "getpwuid_r".
…exity from 30 to the 25 allowed
…exity from 55 to the 25 allowed
…exity from 48 to the 25 allowed
|
Make sure it compiles before we take a look |
There was a problem hiding this comment.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
pre-commit
[pre-commit] reported by reviewdog 🐶
Lines 575 to 661 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 664 to 665 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 667 to 671 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 673 to 677 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 679 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 684 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 691 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 694 to 706 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 711 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 718 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 720 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 721 to 726 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 728 to 729 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 731 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 733 to 786 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 788 to 789 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 791 to 801 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 803 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 808 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 815 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 818 to 830 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 835 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 842 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 844 to 870 in 6821a46
[pre-commit] reported by reviewdog 🐶
Line 872 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 873 to 894 in 6821a46
[pre-commit] reported by reviewdog 🐶
Lines 896 to 897 in 6821a46
| static void check_ns_ew_3d_input(const struct Cell_head *cellhd, | ||
| int row_flag, int col_flag); |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| static void check_ns_ew_3d_input(const struct Cell_head *cellhd, | |
| int row_flag, int col_flag); | |
| static void check_ns_ew_3d_input(const struct Cell_head *cellhd, int row_flag, | |
| int col_flag); |
| check_ns_input(cellhd, row_flag); | ||
| check_ew_input(cellhd, col_flag); |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| check_ns_input(cellhd, row_flag); | |
| check_ew_input(cellhd, col_flag); | |
| check_ns_input(cellhd, row_flag); | |
| check_ew_input(cellhd, col_flag); |
| { | ||
| if (!row_flag) { | ||
| if (cellhd->ns_res <= 0) | ||
| G_fatal_error(_("Illegal n-s resolution value: %g"), cellhd->ns_res); |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| G_fatal_error(_("Illegal n-s resolution value: %g"), cellhd->ns_res); | |
| G_fatal_error(_("Illegal n-s resolution value: %g"), | |
| cellhd->ns_res); |
| { | ||
| if (!col_flag) { | ||
| if (cellhd->ew_res <= 0) | ||
| G_fatal_error(_("Illegal e-w resolution value: %g"), cellhd->ew_res); |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| G_fatal_error(_("Illegal e-w resolution value: %g"), cellhd->ew_res); | |
| G_fatal_error(_("Illegal e-w resolution value: %g"), | |
| cellhd->ew_res); |
| if (cellhd->depths <= 0) | ||
| G_fatal_error(_("Illegal depths value: %d"), cellhd->depths); | ||
| } | ||
|
|
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| if (!name || !*name) { | ||
| struct passwd pwd; | ||
| struct passwd *result = NULL; |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| if (!name || !*name) { | |
| struct passwd pwd; | |
| struct passwd *result = NULL; | |
| if (!name || !*name) { | |
| struct passwd pwd; | |
| struct passwd *result = NULL; |
| long buflen = sysconf(_SC_GETPW_R_SIZE_MAX); | ||
| if (buflen < 0) | ||
| buflen = 16384; /* fallback */ |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| long buflen = sysconf(_SC_GETPW_R_SIZE_MAX); | |
| if (buflen < 0) | |
| buflen = 16384; /* fallback */ | |
| long buflen = sysconf(_SC_GETPW_R_SIZE_MAX); | |
| if (buflen < 0) | |
| buflen = 16384; /* fallback */ |
| if (buflen < 0) | ||
| buflen = 16384; /* fallback */ | ||
|
|
||
| char *buf = G_malloc((size_t)buflen); |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| char *buf = G_malloc((size_t)buflen); | |
| char *buf = G_malloc((size_t)buflen); |
| if (getpwuid_r(getuid(), &pwd, buf, (size_t)buflen, &result) == 0 && | ||
| result && result->pw_name && *result->pw_name) { | ||
| name = G_store(result->pw_name); | ||
| } |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| if (getpwuid_r(getuid(), &pwd, buf, (size_t)buflen, &result) == 0 && | |
| result && result->pw_name && *result->pw_name) { | |
| name = G_store(result->pw_name); | |
| } | |
| if (getpwuid_r(getuid(), &pwd, buf, (size_t)buflen, &result) == 0 && | |
| result && result->pw_name && *result->pw_name) { | |
| name = G_store(result->pw_name); | |
| } |
| G_free(buf); | ||
| } |
There was a problem hiding this comment.
[pre-commit] reported by reviewdog 🐶
| G_free(buf); | |
| } | |
| G_free(buf); | |
| } |
Apologies for the inconvenience, my workflow didn't work as I expected it to. I'm working on fixing the issues in the near future. |
Description
Fix a collection of security, reliability, and maintainability issues
across several core
lib/gismodules, identified by static analysis.Changes by file:
mapset_nme.c%sformat placeholder to prevent buffer overreadopen.cerror.cprefix_stdarray access against negative/overflowing index (×2)error.cctime()withctime_r()mapset_msc.cpathaccess at negative byte offset -1whoami.cgetpwuid()withgetpwuid_r()adj_cellhd.cMotivation and context
These issues were flagged by static analysis (SonarQube). The security
fixes address real vulnerabilities (format string, TOCTOU). The reliability
fixes prevent undefined behaviour from out-of-bounds array access. The
maintainability changes improve thread safety and readability.
How has this been tested?
The changed modules are exercised indirectly through raster operations,
mapset management tools, and integration tests throughout the test suite.
No dedicated unit tests exist for these specific functions.
Types of changes
Checklist