bootcount: fix segfault by checking the funcs are not NULL

Signed-off-by: Hector Palacios <hector.palacios@digi.com>
This commit is contained in:
Hector Palacios 2024-08-20 14:04:12 +02:00
parent aad224ef28
commit b1adc08178
1 changed files with 7 additions and 0 deletions

View File

@ -14,6 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <stdio.h> #include <stdio.h>
@ -162,6 +163,11 @@ int main(int argc, char *argv[]) {
/* Determine platform. */ /* Determine platform. */
platform = get_platform(); platform = get_platform();
pfuncs = &platforms_functions[platform]; pfuncs = &platforms_functions[platform];
if (!pfuncs->read_bootcount || !pfuncs->write_bootcount) {
printf("Platform not supported\n");
ret = -ENOTSUP;
goto end;
}
/* Execute the requested action. */ /* Execute the requested action. */
if (read) { if (read) {
@ -176,5 +182,6 @@ int main(int argc, char *argv[]) {
ret = pfuncs->write_bootcount(0); ret = pfuncs->write_bootcount(0);
} }
end:
return ret; return ret;
} }