Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/raster: fixed security vulnerabilities and weaknesses #3549

Merged
merged 4 commits into from
Apr 7, 2024

Conversation

jadenabrams100
Copy link
Contributor

This PR fixes three vulnerabilities/weaknesses found with older scans of Coverity.

Issue 1208372 in error.c concerns an unbounded read of an environment variable into memory. An attacker could overwrite the environment variable that is accessed by G__home() and exploit it to overflow the buf array.

Issue 1501330 in mapset_msc.c concerns writing into an array that is not null terminated. If the path variable was not null terminated, the write could fill the whole array with data without a null terminator, causing trouble down the line.

Issue 1207344 in raster/r.gwflow/main.c concerns a constant variable guarding dead code. This is not exactly a security vulnerability, but is a code quality issue I was able to easily fix.

@github-actions github-actions bot added raster Related to raster data processing C Related code is in C libraries module labels Apr 1, 2024
lib/gis/mapset_msc.c Outdated Show resolved Hide resolved
marisn
marisn previously approved these changes Apr 2, 2024
@nilason nilason self-assigned this Apr 2, 2024
Copy link
Contributor

@nilason nilason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some suggestion. In general it is advisable to constrain buffer sizes defined by constants like GPATH_MAX to include null terminator (i.e. not to increase it with 1).

lib/gis/error.c Outdated Show resolved Hide resolved
lib/gis/mapset_msc.c Outdated Show resolved Hide resolved
@jadenabrams100
Copy link
Contributor Author

I am not certain why the MacOS job failed.

lib/gis/mapset_msc.c Fixed Show resolved Hide resolved
@echoix
Copy link
Member

echoix commented Apr 3, 2024

I am not certain why the MacOS job failed.

Just to make sure I made a rerun of the job, and still failed early.

The earliest possible error that I was only able to spot was the linker not being able to link libgrass, but didn’t find another more descriptive error in the compilation.

@echoix
Copy link
Member

echoix commented Apr 3, 2024

I'm surprised that another Clang-based job didn't fail. I only see that Travis builds with gcc and clang, but on Ubuntu focal. I thought we had more clang jobs than that.

@nilason
Copy link
Contributor

nilason commented Apr 4, 2024

I am not certain why the MacOS job failed.

In the CI log you can find the reason:

mapset_msc.c:189:5: error: array index 4096 is past the end of the array (that has type 'char[4096]') [-Werror,-Warray-bounds]
    path[GPATH_MAX] = '\0';
    ^    ~~~~~~~~~
mapset_msc.c:186:5: note: array 'path' declared here
    char path[GPATH_MAX] = {'\0'};
    ^
1 error generated.

which is the same issue as the CodeQL reports.

@nilason
Copy link
Contributor

nilason commented Apr 4, 2024

I'm surprised that another Clang-based job didn't fail. I only see that Travis builds with gcc and clang, but on Ubuntu focal. I thought we had more clang jobs than that.

The macOS CI is built with -Wall -Wextra -Wpedantic -Werror, which makes the difference. The gcc CI's have the same build flags, but gcc has different set of warnings activated with those compared to clang.

@echoix
Copy link
Member

echoix commented Apr 6, 2024

Is this ready now that CI passes?

@jadenabrams100
Copy link
Contributor Author

Is this ready now that CI passes?

Yes, it is ready now.

@nilason nilason enabled auto-merge (squash) April 7, 2024 12:59
@nilason nilason merged commit dec4266 into OSGeo:main Apr 7, 2024
26 checks passed
@neteler neteler added this to the 8.4.0 milestone Apr 21, 2024
@neteler neteler changed the title lib raster: fixed security vulnerabilities and weaknesses lib/raster: fixed security vulnerabilities and weaknesses Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C Related code is in C libraries module raster Related to raster data processing
Projects
Development

Successfully merging this pull request may close these issues.

5 participants