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

Compiler errors/warnings on EVS_SendEvent() calls on some architectures #33

Closed
skliper opened this issue Sep 30, 2019 · 11 comments
Closed
Labels
Milestone

Comments

@skliper
Copy link
Contributor

skliper commented Sep 30, 2019

One roadblock to turning on strict compiler settings (such as -Werror) with full error checking is that MANY compiler warnings are generated by printf error checking done by gcc.

The full error checking is VERY USEFUL because it verifies that the argument corresponding to each escape code is the right type, e.g. %s has a string, %d has an integer, etc.

The problem is that we are using the OSAL abstractions such as int32 or uint32. For example, on some systems, printf'ing an int32 needs a "%d" and on other systems it needs a "%ld" depending on whether it was typedef'ed as an int or a long. So fixing an error on one platform by changing the escape code in the format string only generates an error on a different platform.

In order to fix this so that it builds without warnings on all platforms, any argument that ultimately gets passed to any C library printf() call needs to be cast to the right fundamental C type, not the abstracted type, at the call to the variadic function.

Note this is really only an issue for variable argument functions since for normal functions the correct type is known and the compiler automatically casts it when possible. But for variadic C library functions this is not possible so we must explicitly ensure that the argument gets converted to the correct type //for the c library//. GCC is nice enough to implement warnings for this when it is mismatched, we should leverage that.

@skliper skliper added this to the 6.5.0 milestone Sep 30, 2019
@skliper skliper self-assigned this Sep 30, 2019
@skliper skliper added the bug label Sep 30, 2019
@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Imported from trac issue 2. Created by jphickey on 2014-12-18T22:48:50, last modified: 2019-03-05T14:57:55

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by jphickey on 2014-12-19 10:10:20:

Pushed [changeset:84e5ff3e] to address this issue

This change enables the GCC printf error checking on EVS_SendEvent(),EVS_SendEventWithAppId() and ES_WriteToSyslog() calls //if// the OSAL defines the OS_PRINTF macro. The OSAL macro is added in a different commit but the option is #ifdef'ed for compatibility so these changes can be merged separately.

In all cases where the variable argument call is made throughout the code, the arguments are forced (typecast) to the correct fundamental C type as indicated by the corresponding format string. This is absolutely necessary on 64-bit machines where there are a real differences between a normal "int", a "long int" and a "void *".

In addition a couple real security issues/potential buffer overruns are fixed:

  • There were cases where sprintf() was used with a buffer potentially too short, this was extended and also replaced with snprintf().
  • There were two cases (in ES and TBL) where a format string was generated "on-the-fly" and directly passed to WriteToSyslog using user-supplied data -- this is dangerous as the user-supplied string might contain a format character such as %s.

The fix branch name is "trac-2-printf-argcheck"

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by sstrege on 2015-04-03 18:44:29:

Concur with the changes

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by jphickey on 2015-04-06 11:34:52:

This is ready for review/merge

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by acudmore on 2015-04-06 13:44:49:

Concur

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by sduran on 2015-04-06 13:48:09:

recommend accept

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by jwilmot on 2015-04-06 15:14:23:

Concur

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by glimes on 2015-04-07 12:43:58:

Tested changeset [changeset:84e5ff3e] as part of the ic-2015-03-10 merge.

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by glimes on 2015-04-13 15:25:56:

Part of integration candidate 2015-03-10,
committed to cFS CFE Development branch on 2015-04-10
as part of merge [changeset:7d6f6d0].

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by glimes on 2016-02-25 10:17:32:

these will be fixed in CFE 6.5

@skliper
Copy link
Contributor Author

skliper commented Sep 30, 2019

Trac comment by jhageman on 2019-03-05 14:57:55:

Milestone renamed

@skliper skliper closed this as completed Sep 30, 2019
@skliper skliper removed their assignment Sep 30, 2019
dmknutsen pushed a commit that referenced this issue Jan 23, 2020
Fix #32, #34
Reviewed and approved at 2019-12-18 CCB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant