Tíquete #45822

savegame?.c: strlen(NULL)

: 2022-10-11 02:47 Última Atualização: 2023-05-04 10:22

Relator:
Dono:
Tipo:
Estado:
Fechado
Componente:
Marcos:
Prioridade:
5 - Medium
Gravidade:
5 - Medium
Resolução:
Fixed
Arquivo:
2

Details

Clang analyzer gives some warnings about strlen() being called with NULL string in savegame2.c and savegame3.c. I assume these to be some common pattern to be fixed as one bug.

Ticket History (3/7 Histories)

2022-10-11 02:47 Updated by: cazfi
  • New Ticket "savegame?.c: strlen(NULL)" created
2022-10-11 03:23 Updated by: cazfi
Comentário

Reply To cazfi

I assume these to be some common pattern to be fixed as one bug.

The pattern is that there's a sg_failure_ret() macro checking that the string is not NULL, and then separate sg_failure_ret() macro using strlen() to check its length. Seems correct to me, i.e., the report to be a false positive.

2023-04-25 03:46 Updated by: cazfi
Comentário

Reply To cazfi

Reply To cazfi

I assume these to be some common pattern to be fixed as one bug.

The pattern is that there's a sg_failure_ret() macro checking that the string is not NULL, and then separate sg_failure_ret() macro using strlen() to check its length. Seems correct to me, i.e., the report to be a false positive.

Even more generic pattern: sg_failure_ret() macro checking something that should make sure that some latter code should not trip to NULL pointers or similar.

The problem with current sg_failure_ret() is in the order it does things in case of failure:
1. It sets sg_success to FALSE
2. It calls logging function
3. (via sg_check_ret() ) it returns if sg_success is FALSE

The problem here is that compiler/analyzer cannot be sure that the logging function call does not alter sg_success back to TRUE, and thus make sg_check_ret() to let execution to continue.

2023-04-25 03:50 Updated by: cazfi
  • Dono Update from (Nenhum) to cazfi
  • Resolução Update from Nenhum to Accepted
  • Marco Update from (Nenhum) to 3.0.8 (fechado)
2023-05-04 10:22 Updated by: cazfi
  • Estado Update from Aberto to Fechado
  • Resolução Update from Accepted to Fixed

Attachment File List

Editar

Please login to add comment to this ticket » Login