Skip to content

Commit d9bc087

Browse files
committed
XMPMeta.cpp: match types to format strings in OutProc* macros
The numerical OutProc*(num) macros fill in their arguments 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. static_cast<> the macro arguments to the types matching the format string, to get the expected type width on the stack.
1 parent 9215f74 commit d9bc087

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

xmpsdk/src/XMPMeta.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@ static const char * kTenSpaces = " ";
8181

8282
#define OutProcString(str) { status = (*outProc) ( refCon, (str).c_str(), (str).size() ); if ( status != 0 ) goto EXIT; }
8383

84-
#define OutProcULong(num) { snprintf ( buffer, sizeof(buffer), "%lu", (num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
84+
#define OutProcULong(num) { snprintf ( buffer, sizeof(buffer), "%lu", static_cast<unsigned long>(num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
8585
status = (*outProc) ( refCon, buffer, strlen(buffer) ); if ( status != 0 ) goto EXIT; }
8686
#ifdef __APPLE__
87-
#define OutProcHexInt(num) { snprintf ( buffer, sizeof(buffer), "%X", (num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
87+
#define OutProcHexInt(num) { snprintf ( buffer, sizeof(buffer), "%X", static_cast<unsigned int>(num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
8888
status = (*outProc) ( refCon, buffer, strlen(buffer) ); if ( status != 0 ) goto EXIT; }
8989
#else
90-
#define OutProcHexInt(num) { snprintf ( buffer, sizeof(buffer), "%lX", (num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
90+
#define OutProcHexInt(num) { snprintf ( buffer, sizeof(buffer), "%lX", static_cast<unsigned long>(num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
9191
status = (*outProc) ( refCon, buffer, strlen(buffer) ); if ( status != 0 ) goto EXIT; }
9292
#endif
9393

94-
#define OutProcHexByte(num) { snprintf ( buffer, sizeof(buffer), "%.2X", (num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
94+
#define OutProcHexByte(num) { snprintf ( buffer, sizeof(buffer), "%.2X", static_cast<unsigned int>(num) ); /* AUDIT: Using sizeof for snprintf length is safe */ \
9595
status = (*outProc) ( refCon, buffer, strlen(buffer) ); if ( status != 0 ) goto EXIT; }
9696

9797
static const char * kIndent = " ";

0 commit comments

Comments
 (0)