Skip to content

Commit e510d39

Browse files
authored
Fix potential buffer overflow (#22216)
* Fix potential buffer overflow As reported here: https://github.com/root-project/root/security/code-scanning/1845 - Fixes #22213 - Fixes https://github.com/root-project/root/security/code-scanning/1845 * Remove unused variable
1 parent ada74fa commit e510d39

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

net/net/src/TApplicationServer.cxx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ Int_t TApplicationServer::ReceiveFile(const char *file, Bool_t bin, Long64_t siz
737737
}
738738

739739
const Int_t kMAXBUF = 16384; //32768 //16384 //65536;
740-
char buf[kMAXBUF], cpy[kMAXBUF];
740+
char buf[kMAXBUF];
741741

742742
Int_t left, r;
743743
Long64_t filesize = 0;
@@ -755,18 +755,13 @@ Int_t TApplicationServer::ReceiveFile(const char *file, Bool_t bin, Long64_t siz
755755
Int_t w;
756756

757757
if (!bin) {
758-
Int_t k = 0, i = 0, j = 0;
759-
char *q;
760-
while (i < r) {
761-
if (p[i] == '\r') {
762-
i++;
763-
k++;
758+
Int_t j = 0;
759+
for (Int_t i = 0; i < r; ++i) {
760+
if (p[i] != '\r') {
761+
p[j++] = p[i];
764762
}
765-
cpy[j++] = buf[i++];
766763
}
767-
q = cpy;
768-
r -= k;
769-
w = write(fd, q, r);
764+
w = write(fd, p, j);
770765
} else {
771766
w = write(fd, p, r);
772767
}

0 commit comments

Comments
 (0)