Browse Source

qfile-utils: do not write a random extra byte

readlink(2) does not write a terminating NUL, and the read side
will already place a NUL after whatever it receives.
While it seems odd that this would be buggy (ie, synlinks on
the ohter side would be pointing to the wrong filename, though
I guess if we're lucky and the stack had a 0 byte at the right
place, symlink(2) would do what was expected), my reading of
the code tells me this patch is right. Needs testing to double
check.
Vincent Penquerc'h 10 years ago
parent
commit
df7c431d0b
1 changed files with 2 additions and 2 deletions
  1. 2 2
      qubes-rpc/qfile-utils.c

+ 2 - 2
qubes-rpc/qfile-utils.c

@@ -175,9 +175,9 @@ int single_file_processor(const char *filename, const struct stat *st)
 		char name[st->st_size + 1];
 		if (readlink(filename, name, sizeof(name)) != st->st_size)
 			gui_fatal("readlink %s", filename);
-		hdr.filelen = st->st_size + 1;
+		hdr.filelen = st->st_size;
 		write_headers(&hdr, filename);
-		if (!write_all_with_crc(1, name, st->st_size + 1)) {
+		if (!write_all_with_crc(1, name, st->st_size)) {
 			set_block(0);
 			wait_for_result();
 			exit(1);