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

Sprintf considered harmful #27

Open
timj opened this issue Mar 10, 2014 · 2 comments
Open

Sprintf considered harmful #27

timj opened this issue Mar 10, 2014 · 2 comments
Labels

Comments

@timj
Copy link
Member

timj commented Mar 10, 2014

In commit 0b368ea we are left with the following code:

/* Get the name for the Q NDF for this block. Start of with "Q" followed by
   the block index. */
                  iblock++;
                  nc = sprintf( ndfname, "Q%d", iblock );

/* Append the subarray name to the NDF name. */
                  nc += sprintf( ndfname + nc, "_%s", subarray );

/* Append the chunk index to the NDF name. */
                  nc += sprintf( ndfname + nc, "_%d", (int) ichunk );

in smurf_calcqu.c. The second two lines were historically protected by if-statements and so were distinct. Now this could all be done in a single sprintf. Furthermore, one_snprintf should be used to protect against buffer overflow.

There are many unprotected sprintf uses in SMURF. Particular care should be taken when using %s.

@timj timj added the bug label Mar 10, 2014
@MalcolmCurrie
Copy link
Contributor

Please could you expand the recommendations in http://starlink.jach.hawaii.edu/starlink/StarlinkCProgramming.

@timj
Copy link
Member Author

timj commented Mar 11, 2014

I have added an entry about ONE.

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

2 participants