diff options
author | Martin Storsjo <martin@martin.st> | 2015-05-20 00:12:28 +0300 |
---|---|---|
committer | Marco Nelissen <marcone@google.com> | 2015-06-25 08:25:52 -0700 |
commit | 85a43d2fcf9572145dd013a1a43ff11b327bcbbc (patch) | |
tree | 971ba34dd10fcbfb25a374a3539d06cef349aee4 /decoder | |
parent | c6488980b2be422832fb9fa0c0e2c0928d825a35 (diff) | |
download | android_external_libavc-85a43d2fcf9572145dd013a1a43ff11b327bcbbc.tar.gz android_external_libavc-85a43d2fcf9572145dd013a1a43ff11b327bcbbc.tar.bz2 android_external_libavc-85a43d2fcf9572145dd013a1a43ff11b327bcbbc.zip |
Fix string handling for generating version strings
Don't do concatenation with strncat; the length parameter in strncat
is only for how many chars to append at most, not for the full output
buffer size. To safely use strncat, one would have to do
strncat(buf, str, sizeof(buf) - strlen(buf)).
By using snprintf, we guarantee that the buffer is null terminated, and
we don't need to use strnlen at all.
(If compatibility with older MSVC versions that lack snprintf, one
can use _snprintf instead and manually add the null termination.)
Change-Id: I1c2322c7a406ddd5e6551a96c460da60deeffda1
Diffstat (limited to 'decoder')
-rw-r--r-- | decoder/ih264d_api.c | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/decoder/ih264d_api.c b/decoder/ih264d_api.c index 424b660..332e4ad 100644 --- a/decoder/ih264d_api.c +++ b/decoder/ih264d_api.c @@ -107,18 +107,9 @@ #define CODEC_VENDOR "ITTIAM" #define MAXVERSION_STRLEN 511 #define VERSION(version_string, codec_name, codec_release_type, codec_release_ver, codec_vendor) \ - strncpy(version_string,"@(#)Id:", MAXVERSION_STRLEN); \ - strncat(version_string,codec_name, MAXVERSION_STRLEN); \ - strncat(version_string,"_", MAXVERSION_STRLEN); \ - strncat(version_string,codec_release_type, MAXVERSION_STRLEN); \ - strncat(version_string," Ver:", MAXVERSION_STRLEN); \ - strncat(version_string,codec_release_ver, MAXVERSION_STRLEN); \ - strncat(version_string," Released by ", MAXVERSION_STRLEN); \ - strncat(version_string,codec_vendor, MAXVERSION_STRLEN); \ - strncat(version_string," Build: ", MAXVERSION_STRLEN); \ - strncat(version_string,__DATE__, MAXVERSION_STRLEN); \ - strncat(version_string," @ ", MAXVERSION_STRLEN); \ - strncat(version_string,__TIME__, MAXVERSION_STRLEN); + snprintf(version_string, MAXVERSION_STRLEN, \ + "@(#)Id:%s_%s Ver:%s Released by %s Build: %s @ %s", \ + codec_name, codec_release_type, codec_release_ver, codec_vendor, __DATE__, __TIME__) #define MAX_NAL_UNIT_SIZE MAX((H264_MAX_FRAME_HEIGHT * H264_MAX_FRAME_HEIGHT),MIN_NALUNIT_SIZE) #define MIN_NALUNIT_SIZE 200000 @@ -3365,7 +3356,7 @@ WORD32 ih264d_get_version(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op) return (IV_FAIL); } - version_string_len = strnlen(version_string, MAXVERSION_STRLEN) + 1; + version_string_len = strlen(version_string) + 1; if(ps_ip->u4_version_buffer_size >= version_string_len) //(WORD32)sizeof(sizeof(version_string))) { |