Incidencia #45822

savegame?.c: strlen(NULL)

Abrir Fecha: 2022-10-11 02:47 Última actualización: 2023-05-04 10:22

Informador:
Propietario:
Tipo:
Estado:
Cerrado
Componente:
Prioridad:
5 - Medium
Gravedad:
5 - Medium
Resolución:
Fixed
Fichero:
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
Comentario

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
Comentario

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
  • Propietario Update from (Ninguno) to cazfi
  • Resolución Update from Ninguno to Accepted
  • Hito Update from (Ninguno) to 3.0.8 (cerrado)
2023-05-04 10:22 Updated by: cazfi
  • Estado Update from Open to Cerrado
  • Resolución Update from Accepted to Fixed

Attachment File List

Editar

Please login to add comment to this ticket » Entrar