From 3927bd3c0d16367eef862660f7b7a5309b66a5a1 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Sun, 27 Nov 2011 01:45:21 -0500 Subject: [PATCH] Prevent string overflow by replacing usage of strcpy by strncpy CID 8951, CID 10733, CID 10734, CID 10735, CID 10736, CID 10737, CID 10738, CID 10739 --- src/add-ons/translators/exr/EXRTranslator.cpp | 3 ++- src/add-ons/translators/gif/GIFTranslator.cpp | 5 +++-- src/add-ons/translators/png/PNGTranslator.cpp | 3 ++- src/add-ons/translators/ppm/PPMTranslator.cpp | 5 +++-- src/add-ons/translators/rtf/RTFTranslator.cpp | 3 ++- src/add-ons/translators/sgi/SGITranslator.cpp | 3 ++- src/add-ons/translators/shared/BaseTranslator.cpp | 3 ++- src/add-ons/translators/stxt/STXTTranslator.cpp | 3 ++- .../translators/wonderbrush/WonderBrushTranslator.cpp | 3 ++- 9 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/add-ons/translators/exr/EXRTranslator.cpp b/src/add-ons/translators/exr/EXRTranslator.cpp index b6618401e4..5caf228570 100644 --- a/src/add-ons/translators/exr/EXRTranslator.cpp +++ b/src/add-ons/translators/exr/EXRTranslator.cpp @@ -98,7 +98,8 @@ EXRTranslator::DerivedIdentify(BPositionIO *stream, outInfo->quality = EXR_IN_QUALITY; outInfo->capability = EXR_IN_CAPABILITY; strcpy(outInfo->MIME, "image/exr"); - strcpy(outInfo->name, B_TRANSLATE("EXR image")); + strncpy(outInfo->name, B_TRANSLATE("EXR image"), + sizeof(outInfo->name)); } } catch (const std::exception &e) { return B_NO_TRANSLATOR; diff --git a/src/add-ons/translators/gif/GIFTranslator.cpp b/src/add-ons/translators/gif/GIFTranslator.cpp index 420545ade4..40196210fe 100644 --- a/src/add-ons/translators/gif/GIFTranslator.cpp +++ b/src/add-ons/translators/gif/GIFTranslator.cpp @@ -170,14 +170,15 @@ Identify(BPositionIO *inSource, const translation_format *inFormat, outInfo->type = GIF_TYPE; outInfo->quality = 0.8; outInfo->capability = 0.8; - strcpy(outInfo->name, B_TRANSLATE("GIF image")); + strncpy(outInfo->name, B_TRANSLATE("GIF image"), sizeof(outInfo->name)); strcpy(outInfo->MIME, "image/gif"); } else { outInfo->type = B_TRANSLATOR_BITMAP; outInfo->quality = 0.3; outInfo->capability = 0.3; - strcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format (GIFTranslator)")); + strncpy(outInfo->name, B_TRANSLATE("Be Bitmap Format (GIFTranslator)"), + sizeof(outInfo->name)); strcpy(outInfo->MIME, "image/x-be-bitmap"); } return B_OK; diff --git a/src/add-ons/translators/png/PNGTranslator.cpp b/src/add-ons/translators/png/PNGTranslator.cpp index b49bd2729b..9d2034daf2 100644 --- a/src/add-ons/translators/png/PNGTranslator.cpp +++ b/src/add-ons/translators/png/PNGTranslator.cpp @@ -238,7 +238,8 @@ identify_png_header(BPositionIO *inSource, translator_info *outInfo) outInfo->quality = PNG_IN_QUALITY; outInfo->capability = PNG_IN_CAPABILITY; strcpy(outInfo->MIME, "image/png"); - strcpy(outInfo->name, B_TRANSLATE("PNG image")); + strncpy(outInfo->name, B_TRANSLATE("PNG image"), + sizeof(outInfo->name)); } return B_OK; diff --git a/src/add-ons/translators/ppm/PPMTranslator.cpp b/src/add-ons/translators/ppm/PPMTranslator.cpp index 5e38d46cfb..0bb237cadb 100644 --- a/src/add-ons/translators/ppm/PPMTranslator.cpp +++ b/src/add-ons/translators/ppm/PPMTranslator.cpp @@ -280,14 +280,15 @@ Identify( /* required */ outInfo->type = PPM_TYPE; outInfo->quality = 0.3; /* no alpha, etc */ outInfo->capability = 0.8; /* we're pretty good at PPM reading, though */ - strcpy(outInfo->name, B_TRANSLATE("PPM image")); + strncpy(outInfo->name, B_TRANSLATE("PPM image"), sizeof(outInfo->name)); strcpy(outInfo->MIME, "image/x-portable-pixmap"); } else { outInfo->type = B_TRANSLATOR_BITMAP; outInfo->quality = 0.4; /* B_TRANSLATOR_BITMAP can do alpha, at least */ outInfo->capability = 0.8; /* and we might not know many variations thereof */ - strcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format (PPMTranslator)")); + strncpy(outInfo->name, B_TRANSLATE("Be Bitmap Format (PPMTranslator)"), + sizeof(outInfo->name)); strcpy(outInfo->MIME, "image/x-be-bitmap"); /* this is the MIME type of B_TRANSLATOR_BITMAP */ } return B_OK; diff --git a/src/add-ons/translators/rtf/RTFTranslator.cpp b/src/add-ons/translators/rtf/RTFTranslator.cpp index e209cc95ac..ca560e0b61 100644 --- a/src/add-ons/translators/rtf/RTFTranslator.cpp +++ b/src/add-ons/translators/rtf/RTFTranslator.cpp @@ -135,7 +135,8 @@ RTFTranslator::Identify(BPositionIO *stream, info->group = B_TRANSLATOR_TEXT; info->quality = RTF_IN_QUALITY; info->capability = RTF_IN_CAPABILITY; - strcpy(info->name, B_TRANSLATE("RichTextFormat file")); + strncpy(info->name, B_TRANSLATE("RichTextFormat file"), + sizeof(info->name)); strcpy(info->MIME, "text/rtf"); return B_OK; diff --git a/src/add-ons/translators/sgi/SGITranslator.cpp b/src/add-ons/translators/sgi/SGITranslator.cpp index 1e5c5e3da3..f9aaefa939 100644 --- a/src/add-ons/translators/sgi/SGITranslator.cpp +++ b/src/add-ons/translators/sgi/SGITranslator.cpp @@ -203,7 +203,8 @@ identify_sgi_header(BPositionIO *inSource, translator_info *outInfo, uint32 outT outInfo->quality = SGI_IN_QUALITY; outInfo->capability = SGI_IN_CAPABILITY; strcpy(outInfo->MIME, "image/sgi"); - strcpy(outInfo->name, B_TRANSLATE("SGI image")); + strncpy(outInfo->name, B_TRANSLATE("SGI image"), + sizeof(outInfo->name)); } } else { delete sgiImage; diff --git a/src/add-ons/translators/shared/BaseTranslator.cpp b/src/add-ons/translators/shared/BaseTranslator.cpp index 5a33fcce2f..9aec0c7570 100644 --- a/src/add-ons/translators/shared/BaseTranslator.cpp +++ b/src/add-ons/translators/shared/BaseTranslator.cpp @@ -305,7 +305,8 @@ BaseTranslator::identify_bits_header(BPositionIO *inSource, outInfo->group = B_TRANSLATOR_BITMAP; outInfo->quality = 0.2; outInfo->capability = 0.2; - strcpy(outInfo->name, B_TRANSLATE("Be Bitmap Format")); + strncpy(outInfo->name, B_TRANSLATE("Be Bitmap Format"), + sizeof(outInfo->name)); strcpy(outInfo->MIME, "image/x-be-bitmap"); // Look for quality / capability info in fInputFormats diff --git a/src/add-ons/translators/stxt/STXTTranslator.cpp b/src/add-ons/translators/stxt/STXTTranslator.cpp index 8b5884b3ec..f466a72cf8 100644 --- a/src/add-ons/translators/stxt/STXTTranslator.cpp +++ b/src/add-ons/translators/stxt/STXTTranslator.cpp @@ -860,7 +860,8 @@ identify_stxt_header(const TranslatorStyledTextStreamHeader &header, outInfo->group = B_TRANSLATOR_TEXT; outInfo->quality = STXT_IN_QUALITY; outInfo->capability = STXT_IN_CAPABILITY; - strcpy(outInfo->name, B_TRANSLATE("Be styled text file")); + strncpy(outInfo->name, B_TRANSLATE("Be styled text file"), + sizeof(outInfo->name)); strcpy(outInfo->MIME, "text/x-vnd.Be-stxt"); return B_OK; diff --git a/src/add-ons/translators/wonderbrush/WonderBrushTranslator.cpp b/src/add-ons/translators/wonderbrush/WonderBrushTranslator.cpp index cee8b0d0d8..523ac1c4c5 100644 --- a/src/add-ons/translators/wonderbrush/WonderBrushTranslator.cpp +++ b/src/add-ons/translators/wonderbrush/WonderBrushTranslator.cpp @@ -134,7 +134,8 @@ identify_wbi_header(BPositionIO* inSource, translator_info* outInfo, outInfo->quality = WBI_IN_QUALITY; outInfo->capability = WBI_IN_CAPABILITY; strcpy(outInfo->MIME, "image/x-wonderbrush"); - strcpy(outInfo->name, B_TRANSLATE("WonderBrush image")); + strncpy(outInfo->name, B_TRANSLATE("WonderBrush image"), + sizeof(outInfo->name)); } } else { delete wbImage;