Skip to content

Commit 6156349

Browse files
committed
XMPMeta.cpp: fix macro to cast argument to match type
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.
1 parent 9215f74 commit 6156349

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

xmpsdk/src/XMPMeta.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static const char * kTenSpaces = " ";
8787
#define OutProcHexInt(num) { snprintf ( buffer, sizeof(buffer), "%X", (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", (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

0 commit comments

Comments
 (0)