prevent potential buffer overflow

This commit is contained in:
Kalamatee 2022-04-12 23:56:16 +01:00 committed by deadwood
parent 8670689d2c
commit 6c92741646
3 changed files with 24 additions and 11 deletions

View File

@ -1,15 +1,16 @@
# Copyright © 2003, The AROS Development Team. All rights reserved.
# Copyright © 2003-2022, The AROS Development Team. All rights reserved.
# $Id$
include $(TOP)/config/make.cfg
USER_CFLAGS := -Wall -Wstrict-prototypes '-DVERSION="1.37"' -g -O2
USER_CPPFLAGS := '-DVERSION="1.39"'
USER_CFLAGS := -Wall -Wstrict-prototypes -g -O2
all : $(FD2INLINE)
$(FD2INLINE) : fd2inline.c
@$(ECHO) "Compiling $(notdir $@)..."
@$(HOST_CC) $(HOST_CFLAGS) $(USER_CFLAGS) $< -o $@
@$(HOST_CC) $(HOST_CFLAGS) $(USER_CPPFLAGS) $(USER_CFLAGS) $< -o $@
clean:
@$(RM) -f $(FD2INLINE)

View File

@ -32,7 +32,7 @@ CFLAGS = $(DEFS) -Wall -Wstrict-prototypes \
LDFLAGS = @LDFLAGS@
# Used when building fd2inline, fd2inline.guide and the archives.
VERSION = 1.37
VERSION = 1.39
AMIGAOS_FD_PATH = @amigaos_fd_path@
AMIGAOS_HEADER_PATH = @amigaos_header_path@

View File

@ -21,7 +21,7 @@
* Version 1.3x by Martin Blom
* See fd2inline.guide/fd2inline.info for details.
*
* version 1.38 by AROS development team
* version 1.39 by AROS development team
*
*****************************************************************************/
@ -3121,12 +3121,24 @@ main(int argc, char** argv)
{
char *str=fdfilename+strlen(fdfilename)-8;
while (str!=fdfilename && str[-1]!='/' && str[-1]!=':')
str--;
//lcs strncpy(BaseNamL, str, strlen(str)-7);
strncpy(BaseNamU, str, strlen(str)-7);
BaseNamU[strlen(str)-7]='\0';
strcpy(BaseNamL, BaseNamU);
strcpy(BaseNamC, BaseNamU);
str--;
int basenameLen = strlen(str)-7;
if (basenameLen < sizeof(BaseNamU))
{
char tmpchr = str[basenameLen];
str[basenameLen] = '\0';
strncpy(BaseNamU, str, sizeof(BaseNamU) -1);
str[basenameLen] = tmpchr;
BaseNamU[basenameLen]='\0';
strcpy(BaseNamL, BaseNamU);
strcpy(BaseNamC, BaseNamU);
}
else
{
str[basenameLen] = '\0';
fprintf(stderr, "'%s' too long.\n", str);
return EXIT_FAILURE;
}
}
else
{