The current implementation always searches for the file in PATH
if it is not an absolute path.
This prevents executing relative paths like ./executable.
As specified by exec(3) the p-family of exec functions only search if
the filename does not contain slash '/' characters.
If there is enough space in an inode but the file grows the
inode is never written back to the device and thus the new size is
not persisted.
int fd = creat("foo", 660);
write(fd, "foo", 3); // New blocks are allocated and inode written back
write(fd, "\n", 1); // size is adapted but not written back
close(fd);
// Reading the file afterwards will only return "foo".
The code snippet reproduces the bug.
This is fixed by always writing the inode back to the device if
the size is updated.
New blocks for an inode are allocated when data blocks
should be written and not enough blocks are allocated yet
or during allocating new direntries in ext2_allocate_direntry.
When writing the first time to a newly created file (inode.size==0),
new blocks must be allocated and the inode size is erroneously set to
(blocks_count / fs->blocks_per_block_count) * fs->block_size
regardless of the actually written data.
int fd = creat("foo", 0660);
write(fd, "foo", 3);
This code snippet will create a new inode with size 4096 instead
of the correct size 3.
ext2_write_inode_data will correctly set the size to 3.
However, ext2_allocate_block called by ext2_write_inode_block will
set the inode size to 4096.
This is fixed by removing the size update during ext2_allocate_block.
This reduces the required code in man and additionally,
replaces the old broken read/puts implementation.
Puts expects a null-terminated string, but write does not return
a null-terminted string.
Using puts to output data retrieved through write is broken.
Puts expects a null-terminated string, which is not returned by read.
Use write to exactly output the data previously read.
creat.2 is supposed to be equivalent to open.2 with the
flags O_WRONLY|O_CREAT|O_TRUNC.
However, in MentOS the fd returned by creat.2 has no flags whatsoever
and is thus not writable.
Set the flags of the file descriptor before returning it.
@@ -40,6 +40,7 @@ int main(int argc, char *argv[])
}
elseif(argc==2)
{
char*pager="cat";
charfilepath[PATH_MAX];
strcpy(filepath,"/usr/share/man/");
strcat(filepath,argv[1]);
@@ -47,23 +48,11 @@ int main(int argc, char *argv[])
intfd=open(filepath,O_RDONLY,42);
if(fd<0)
{
printf("%s: No manual entry for %s\n\n",argv[0],argv[1]);
}
else
{
// Prepare the buffer for reading the man file.
charbuffer[BUFSIZ];
// Put on the standard output the characters.
while(read(fd,buffer,BUFSIZ)>0)
{
puts(buffer);
}
// Close the file descriptor.
close(fd);
// Terminate with a pair of newlines.
putchar('\n');
putchar('\n');
printf("%s: No manual entry for %s\n",argv[0],argv[1]);
exit(1);
}
close(fd);
execlp(pager,pager,filepath);
}
return0;
}
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.