mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Harden strcpy calls.
This commit is contained in:
parent
8fef8f7bb1
commit
3d091f39bf
3 changed files with 5 additions and 11 deletions
|
@ -245,11 +245,7 @@ int main(int argc, char* argv[])
|
||||||
if ( output_path )
|
if ( output_path )
|
||||||
guard = strdup(output_path);
|
guard = strdup(output_path);
|
||||||
else if ( 2 <= argc && strcmp(argv[1], "-") != 0 )
|
else if ( 2 <= argc && strcmp(argv[1], "-") != 0 )
|
||||||
{
|
asprintf(&guard, "%s_H", argv[1]);
|
||||||
guard = (char*) malloc(strlen(argv[1]) + 2 + 1);
|
|
||||||
strcpy(guard, argv[1]);
|
|
||||||
strcat(guard, "_H");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
guard = strdup("CARRAY_H");
|
guard = strdup("CARRAY_H");
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,6 @@ extern "C" char* dirname(char* path)
|
||||||
while ( 1 <= path_len && path[path_len-1] == '/' )
|
while ( 1 <= path_len && path[path_len-1] == '/' )
|
||||||
path[--path_len] = '\0';
|
path[--path_len] = '\0';
|
||||||
if ( !path[0] )
|
if ( !path[0] )
|
||||||
strcpy(path, "/");
|
path[0] = '/', path[1] = '\0';
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,12 +266,10 @@ int handle_entry(const char* path, const char* name, unsigned char type)
|
||||||
return 0;
|
return 0;
|
||||||
if ( isdotfile && !option_show_dotfiles && !option_directory )
|
if ( isdotfile && !option_show_dotfiles && !option_directory )
|
||||||
return 0;
|
return 0;
|
||||||
char* fullpath = new char[strlen(path) + 1 + strlen(name) + 1];
|
char* fullpath;
|
||||||
strcpy(fullpath, path);
|
asprintf(&fullpath, "%s/%s", path, name);
|
||||||
strcat(fullpath, "/");
|
|
||||||
strcat(fullpath, name);
|
|
||||||
int result = handle_entry_internal(fullpath, name, type);
|
int result = handle_entry_internal(fullpath, name, type);
|
||||||
delete[] fullpath;
|
free(fullpath);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue