Skip to content

Commit

Permalink
XMPMeta.cpp: fix macro to cast argument to match type
Browse files Browse the repository at this point in the history
The OutProcHexInt(num) macro fills in its argument via
snprintf's "..." varargs part, and the type at the use
site depends on the passed-in types.  This might cause
wrong types on the stack that cause undefined behavior
in the snprintf() function, and reading past memory,
outputting garbage.

Cast the macro argument to (long) to match the %lX
format string first, to get the expected type width.
  • Loading branch information
mandree committed Jul 1, 2023
1 parent 9215f74 commit 6156349
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion xmpsdk/src/XMPMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static const char * kTenSpaces = " ";
#define OutProcHexInt(num) { snprintf ( buffer, sizeof(buffer), "%X", (num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
status = (*outProc) ( refCon, buffer, strlen(buffer) ); if ( status != 0 ) goto EXIT; }
#else
#define OutProcHexInt(num) { snprintf ( buffer, sizeof(buffer), "%lX", (num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
#define OutProcHexInt(num) { snprintf ( buffer, sizeof(buffer), "%lX", (long)(num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
status = (*outProc) ( refCon, buffer, strlen(buffer) ); if ( status != 0 ) goto EXIT; }
#endif

Expand Down

0 comments on commit 6156349

Please sign in to comment.