Skip to content

[BUG] Possible latent bug: dereference of NULL 'pxFile' in ff_file.c #60

Closed
@carlk3

Description

@carlk3

Describe the bug
A concise description of what the bug is. If possible, that is the code is not proprietary, please upload the code in a GitHub fork such that we can reproduce the bug.

Compiling ff_file.c with
arm-none-eabi-gcc.exe (GNU Tools for STM32 11.3.rel1.20230912-1600) 11.3.1 20220712
and option -fanalyzer I get this warning:

Lab-Project-FreeRTOS-FAT/ff_file.c:332:24: warning: dereference of NULL 'pxFile' [CWE-476] [-Wanalyzer-null-dereference]
  332 |         pxFile->ucMode = ucMode;
      |         ~~~~~~~~~~~~~~~^~~~~~~~
  'FF_Move': events 1-6
    |
    |  882 |     FF_Error_t FF_Move( FF_IOManager_t * pxIOManager,
    |      |                ^~~~~~~
    |      |                |
    |      |                (1) entry to 'FF_Move'
    |......
    |  903 |     if( pxIOManager == NULL )
    |      |       ~         
    |      |       |
    |      |       (2) following 'false' branch (when 'pxIOManager' is non-NULL)...
    |......
    |  909 |         else if( ( pxIOManager->ucFlags & FF_IOMAN_DEVICE_IS_EXTRACTED ) != 0 )
    |      |              ~~~
    |      |              | |
    |      |              | (4) following 'false' branch...
    |      |              (3) ...to here
    |......
    |  917 |         pxDestFile = FF_Open( pxIOManager, szDestinationFile, FF_MODE_READ, &xError );
    |      |         ~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |         |            |
    |      |         |            (6) calling 'FF_Open' from 'FF_Move'
    |      |         (5) ...to here
    |
    +--> 'FF_Open': events 7-16
           |
           |  227 |     FF_FILE * FF_Open( FF_IOManager_t * pxIOManager,
           |      |               ^~~~~~~
           |      |               |
           |      |               (7) entry to 'FF_Open'
           |......
           |  260 |     if( ( ucMode & FF_MODE_CREATE ) != 0 )
           |      |       ~        
           |      |       |
           |      |       (8) following 'false' branch...
           |......
           |  265 |     if( pxIOManager == NULL )
           |      |     ~~~        
           |      |     | |
           |      |     | (10) following 'false' branch (when 'pxIOManager' is non-NULL)...
           |      |     (9) ...to here
           |......
           |  273 |         else if( ( pxIOManager->ucFlags & FF_IOMAN_DEVICE_IS_EXTRACTED ) != 0 )
           |      |              ~~~
           |      |              | |
           |      |              | (12) following 'false' branch...
           |      |              (11) ...to here
           |......
           |  280 |         xError = FF_ERR_NONE;
           |      |         ~~~~~~ 
           |      |         |
           |      |         (13) ...to here
           |......
           |  300 |         if( xIndex == 0 )
           |      |           ~    
           |      |           |
           |      |           (14) following 'false' branch (when 'xIndex != 0')...
           |......
           |  308 |         FF_CreateShortName( &xFindParams, pcFileName );
           |      |         ~~~~~~~~~~~~~~~~~~
           |      |         |
           |      |         (15) ...to here
           |......
           |  315 |             if( ( ucMode & FF_MODE_WRITE ) != 0 )
           |      |               ~
           |      |               |
           |      |               (16) following 'false' branch...
           |
         'FF_Open': event 17
           |
           |cc1.exe:
           | (17): ...to here
           |
         'FF_Open': events 18-20
           |
           |  329 |     if( FF_isERR( xError ) == pdFALSE )
           |      |       ^
           |      |       |
           |      |       (18) following 'true' branch...
           |......
           |  332 |         pxFile->ucMode = ucMode;
           |      |         ~~~~~~~~~~~~~~~~~~~~~~~
           |      |         |              |
           |      |         |              (20) dereference of NULL 'pxFile'
           |      |         (19) ...to here
           |

Target

  • Development board: [e.g. HiFive11 RevB]

NUCLEO-L496ZG

  • Instruction Set Architecture: [e.g. RV32IMAC]

ARMv7-M

  • IDE and version: [e.g. Freedom Studio 4.12.0.2019-08-2]

STM32CubeIDE

Version: 1.14.0
Build: 19471_20231121_1200 (UTC)

  • Toolchain and version: [e.g. riscv64-unknown-elf-gcc-8.3.0-2019.08.0]

GNU Tools for STM32 11.3.rel1.20230912-1600

Host

  • Host OS: [e.g. MacOS]

FreeRTOS 10.6.0

  • Version: [e.g. Mojave 10.14.6]

To Reproduce

  • Use project ... and configure with ...
  • Run on ... and could observe ...

Expected behavior
A concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Wireshark logs
To help us identify the issue and/or reproduce it, please attach Wireshark logs if applicable.

Additional context
Add any other context about the problem here.
e.g. code snippet to reproduce the issue.
e.g. stack trace, memory dump, debugger log, and many etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions