[FFmpeg-devel] [PATCH 2/2] ffserver_config: replace strtod by av_strtod and correct undefined behavior
Ganesh Ajjanagadde
gajjanagadde at gmail.com
Fri Nov 13 03:46:05 CET 2015
This uses av_strtod for added flexibility, and av_rint64_clip for ensuring that
no undefined behavior gets invoked.
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
---
ffserver_config.c | 21 +++++----------------
1 file changed, 5 insertions(+), 16 deletions(-)
diff --git a/ffserver_config.c b/ffserver_config.c
index 9fc1f00..443e71d 100644
--- a/ffserver_config.c
+++ b/ffserver_config.c
@@ -19,6 +19,7 @@
*/
#include <float.h>
+#include "libavutil/eval.h"
#include "libavutil/opt.h"
#include "libavutil/parseutils.h"
#include "libavutil/avstring.h"
@@ -757,7 +758,7 @@ static int ffserver_parse_config_feed(FFServerConfig *config, const char *cmd,
} else {
WARNING("Truncate N syntax in configuration file is deprecated. "
"Use Truncate alone with no arguments.\n");
- feed->truncate = strtod(arg, NULL);
+ feed->truncate = av_rint64_clip(av_strtod(arg, NULL), INT_MIN, INT_MAX);
}
} else if (!av_strcasecmp(cmd, "FileMaxSize")) {
char *p1;
@@ -765,22 +766,10 @@ static int ffserver_parse_config_feed(FFServerConfig *config, const char *cmd,
ffserver_get_arg(arg, sizeof(arg), p);
p1 = arg;
- fsize = strtod(p1, &p1);
- switch(av_toupper(*p1)) {
- case 'K':
- fsize *= 1024;
- break;
- case 'M':
- fsize *= 1024 * 1024;
- break;
- case 'G':
- fsize *= 1024 * 1024 * 1024;
- break;
- default:
+ fsize = av_strtod(p1, &p1);
+ if (!fsize || fabs(fsize) == HUGE_VAL)
ERROR("Invalid file size: '%s'\n", arg);
- break;
- }
- feed->feed_max_size = (int64_t)fsize;
+ feed->feed_max_size = av_rint64_clip(fsize, INT64_MIN, INT64_MAX);
if (feed->feed_max_size < FFM_PACKET_SIZE*4) {
ERROR("Feed max file size is too small. Must be at least %d.\n",
FFM_PACKET_SIZE*4);
--
2.6.2
More information about the ffmpeg-devel
mailing list