Skip to content

Commit

Permalink
snprintf fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlf committed Jan 17, 2022
1 parent 586e817 commit 3c38f1a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
3 changes: 2 additions & 1 deletion applications/mp4box/fileimport.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,8 @@ GF_Err import_file(GF_ISOFile *dest, char *inName, u32 import_flags, GF_Fraction
}
}
else if (!strnicmp(ext + 1, "dv-profile=", 11)) {
strncpy(dv_profile, ext + 12, 100);
strncpy(dv_profile, ext + 12, 99);
dv_profile[99]=0;
}
else if (!strnicmp(ext+1, "fullrange=", 10)) {
if (!stricmp(ext+11, "off") || !stricmp(ext+11, "no")) fullrange = 0;
Expand Down
19 changes: 11 additions & 8 deletions src/filters/out_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2018
* Copyright (c) Telecom ParisTech 2018-2022
* All rights reserved
*
* This file is part of GPAC / generic pipe output filter
Expand Down Expand Up @@ -69,7 +69,7 @@ typedef struct

GF_FilterCapability in_caps[2];
char szExt[10];
char szFileName[GF_MAX_PATH];
char *szFileName;
Bool owns_pipe;

} GF_PipeOutCtx;
Expand Down Expand Up @@ -108,7 +108,7 @@ static GF_Err pipeout_open_close(GF_PipeOutCtx *ctx, const char *filename, const
}
gf_filter_pid_resolve_file_template(ctx->pid, szName, szFinalName, file_idx, NULL);

if (!strcmp(szFinalName, ctx->szFileName)
if (ctx->szFileName && !strcmp(szFinalName, ctx->szFileName)
#ifdef WIN32
&& (ctx->pipe != INVALID_HANDLE_VALUE)
#else
Expand Down Expand Up @@ -191,15 +191,15 @@ static GF_Err pipeout_open_close(GF_PipeOutCtx *ctx, const char *filename, const
ctx->fd = open(szFinalName, O_WRONLY );

if (ctx->fd<0) {
GF_LOG(GF_LOG_ERROR, GF_LOG_MMIO, ("[PipeOut] Cannot open output pipe %s: %s\n", ctx->szFileName, gf_errno_str(errno)));
GF_LOG(GF_LOG_ERROR, GF_LOG_MMIO, ("[PipeOut] Cannot open output pipe %s: %s\n", szFinalName, gf_errno_str(errno)));
e = ctx->owns_pipe ? GF_IO_ERR : GF_URL_ERROR;
}
#endif
if (e) {
return e;
}
strncpy(ctx->szFileName, szFinalName, GF_MAX_PATH-1);
ctx->szFileName[GF_MAX_PATH-1] = 0;
if (ctx->szFileName) gf_free(ctx->szFileName);
ctx->szFileName = gf_strdup(szFinalName);
return GF_OK;
}

Expand Down Expand Up @@ -302,8 +302,11 @@ static void pipeout_finalize(GF_Filter *filter)
GF_PipeOutCtx *ctx = (GF_PipeOutCtx *) gf_filter_get_udta(filter);
pipeout_open_close(ctx, NULL, NULL, 0, GF_FALSE);

if (ctx->owns_pipe)
gf_file_delete(ctx->szFileName);
if (ctx->szFileName) {
if (ctx->owns_pipe)
gf_file_delete(ctx->szFileName);
gf_free(ctx->szFileName);
}
}

static GF_Err pipeout_process(GF_Filter *filter)
Expand Down
22 changes: 16 additions & 6 deletions src/filters/out_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* GPAC - Multimedia Framework C SDK
*
* Authors: Jean Le Feuvre
* Copyright (c) Telecom ParisTech 2020
* Copyright (c) Telecom ParisTech 2020-2022
* All rights reserved
*
* This file is part of GPAC / ROUTE output filter
Expand Down Expand Up @@ -950,8 +950,12 @@ static GF_Err routeout_check_service_updates(GF_ROUTEOutCtx *ctx, ROUTEService *


if (serv->manifest) {
snprintf(temp, 1000, " <item metadataURI=\"%s\" version=\"%d\" contentType=\"%s\"/>\n", serv->manifest_name, serv->manifest_version, serv->manifest_mime);
gf_dynstrcat(&payload_text, " <item metadataURI=\"", NULL);
gf_dynstrcat(&payload_text, serv->manifest_name, NULL);
snprintf(temp, 1000, "\" version=\"%d\" contentType=\"", serv->manifest_version);
gf_dynstrcat(&payload_text, temp, NULL);
gf_dynstrcat(&payload_text, serv->manifest_mime, NULL);
gf_dynstrcat(&payload_text, "\"/>\n", NULL);
}

gf_dynstrcat(&payload_text, "</metadataEnvelope>\n\r\n", NULL);
Expand All @@ -973,10 +977,12 @@ static GF_Err routeout_check_service_updates(GF_ROUTEOutCtx *ctx, ROUTEService *
snprintf(temp, 1000, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<BundleDescriptionROUTE xmlns=\"tag:atsc.org,2016:XMLSchemas/ATSC3/Delivery/ROUTEUSD/1.0/\">\n"
" <UserServiceDescription serviceId=\"%d\">\n"
" <Name lang=\"eng\">%s</Name>\n"
" <DeliveryMethod>\n"
" <BroadcastAppService>\n", service_id, service_name);
" <Name lang=\"eng\">", service_id);
gf_dynstrcat(&payload_text, temp, NULL);
gf_dynstrcat(&payload_text, service_name, NULL);
gf_dynstrcat(&payload_text, "</Name>\n"
" <DeliveryMethod>\n"
" <BroadcastAppService>\n", NULL);

for (i=0;i<count; i++) {
rpid = gf_list_get(serv->pids, i);
Expand Down Expand Up @@ -1046,8 +1052,12 @@ static GF_Err routeout_check_service_updates(GF_ROUTEOutCtx *ctx, ROUTEService *
src_ip = szIP;
}

snprintf(temp, 1000, " <RS dIpAddr=\"%s\" dPort=\"%d\" sIpAddr=\"%s\">\n", rlct->ip, rlct->port, src_ip);
gf_dynstrcat(&payload_text, " <RS dIpAddr=\"", NULL);
gf_dynstrcat(&payload_text, rlct->ip, NULL);
snprintf(temp, 1000, "\" dPort=\"%d\" sIpAddr=\"", rlct->port);
gf_dynstrcat(&payload_text, temp, NULL);
gf_dynstrcat(&payload_text, src_ip, NULL);
gf_dynstrcat(&payload_text, "\">\n", NULL);

for (i=0; i<count; i++) {
const GF_PropertyValue *p;
Expand Down
12 changes: 6 additions & 6 deletions src/media_tools/media_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,9 @@ GF_Err gf_media_import_chapters_file(GF_MediaImporter *import)
ts = (h*3600 + m*60+s)*1000;
}
else {
char szTS[20], *tok;
strncpy(szTS, sL, 19);
szTS[19]=0;
char szTS[1025], *tok;
strncpy(szTS, sL, 1024);
szTS[1024]=0;
tok = strrchr(szTS, ' ');
if (tok) {
title = strchr(sL, ' ') + 1;
Expand Down Expand Up @@ -1003,9 +1003,9 @@ GF_Err gf_media_import_chapters_file(GF_MediaImporter *import)
/*CHAPTERX= and CHAPTERXNAME=*/
else if (!strnicmp(sL, "CHAPTER", 7)) {
u32 idx;
char szTemp[20], *str;
strncpy(szTemp, sL, 19);
szTemp[19] = 0;
char szTemp[1025], *str;
strncpy(szTemp, sL, 1024);
szTemp[1024] = 0;
str = strrchr(szTemp, '=');
if (!str) continue;
str[0] = 0;
Expand Down

0 comments on commit 3c38f1a

Please sign in to comment.