Skip to content

Commit dcde847

Browse files
committed
Set maxbuffer limit to child_process to resolve buffer overflows for operations on bulk repos
1 parent 121907e commit dcde847

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

git/gitCommitLogsAPI.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ async function gitCommitLogHandler(repoId, skipLimit = 0) {
99

1010
const totalCommits = await execPromisified(`git log --oneline`, {
1111
cwd: repoPath,
12+
maxBuffer: 1024 * 10240,
1213
windowsHide: true,
1314
})
1415
.then((res) => {
1516
const { stdout, stderr } = res;
16-
if (stderr) {
17-
console.log(stderr);
18-
}
19-
if (res && !res.stderr) {
17+
if (stdout && !stderr) {
2018
const gitLocalTotal = stdout.trim().split("\n").length;
2119
return gitLocalTotal;
2220
} else {
@@ -49,6 +47,7 @@ async function gitCommitLogHandler(repoId, skipLimit = 0) {
4947
{
5048
cwd: repoPath,
5149
windowsHide: true,
50+
maxBuffer: 1024 * 10240,
5251
}
5352
)
5453
.then(async (res) => {

git/gitRepoStatus.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const getGitStatus = async (repoPath) => {
4646
})
4747
.catch((err) => {
4848
console.log("Not a git repo or a new git repo with no commits!");
49-
// console.log(err);
5049
isGitLogAvailable = false;
5150
return isGitLogAvailable;
5251
});
@@ -60,6 +59,7 @@ const getGitStatus = async (repoPath) => {
6059
(await execPromised(`git remote`, {
6160
cwd: repoPath,
6261
windowsHide: true,
62+
maxBuffer: 1024 * 10240,
6363
}).then(({ stdout, stderr }) => {
6464
if (stdout && !stderr) {
6565
const localRemote = stdout.trim().split("\n");
@@ -73,7 +73,6 @@ const getGitStatus = async (repoPath) => {
7373
windowsHide: true,
7474
}).then(({ stdout, stderr }) => {
7575
if (stdout && !stderr) {
76-
console.log("REMOTE :: ", stdout);
7776
return stdout.trim();
7877
} else {
7978
console.log(stderr);
@@ -117,6 +116,7 @@ const getGitStatus = async (repoPath) => {
117116
(await execPromised(`git branch --all`, {
118117
cwd: repoPath,
119118
windowsHide: true,
119+
maxBuffer: 1024 * 10240,
120120
})
121121
.then((res) => {
122122
const { stdout, stderr } = res;
@@ -139,7 +139,11 @@ const getGitStatus = async (repoPath) => {
139139
// Module to get all available branches
140140
gitBranchList =
141141
isGitLogAvailable &&
142-
(await execPromised(`git branch`, { cwd: repoPath, windowsHide: true })
142+
(await execPromised(`git branch`, {
143+
cwd: repoPath,
144+
windowsHide: true,
145+
maxBuffer: 1024 * 10240,
146+
})
143147
.then((res) => {
144148
if (!res.stderr) {
145149
return res.stdout;
@@ -186,28 +190,35 @@ const getGitStatus = async (repoPath) => {
186190
(await execPromised(`git log --oneline`, {
187191
cwd: repoPath,
188192
windowsHide: true,
193+
maxBuffer: 1024 * 10240,
189194
})
190195
.then((res) => {
191196
const { stdout, stderr } = res;
192-
if (stderr) {
193-
console.log(stderr);
194-
}
195-
if (res && !res.stderr) {
196-
const gitLocalTotal = res.stdout.trim().split("\n");
197+
if (stdout && !stderr) {
198+
const gitLocalTotal = stdout.trim().split("\n");
199+
console.log("Total commits: ", gitLocalTotal.length);
197200
if (gitLocalTotal && gitLocalTotal.length > 0) {
198201
gitTotalCommits = gitLocalTotal.length;
199202
} else if (gitLocalTotal.length === 1) {
200203
gitTotalCommits = 1;
201204
}
202205
} else {
203-
gitTotalCommits = 0;
204-
console.log(stderr);
206+
if (!gitTotalCommits) {
207+
gitTotalCommits = 0;
208+
}
209+
console.log(
210+
"ERROR: Error occurred while collcting all commits",
211+
stderr
212+
);
205213
}
206214
return gitTotalCommits;
207215
})
208216
.catch((err) => {
209-
gitTotalCommits = 0;
210-
console.log(err);
217+
if (!gitTotalCommits) {
218+
gitTotalCommits = 0;
219+
}
220+
console.log(typeof err);
221+
console.log("ERROR: Error occurred while collcting all commits");
211222
}));
212223

213224
//Module to get latest git commit
@@ -238,6 +249,7 @@ const getGitStatus = async (repoPath) => {
238249
(await execPromised(`git ls-tree --name-status HEAD`, {
239250
cwd: repoPath,
240251
windowsHide: true,
252+
maxBuffer: 1024 * 10240,
241253
})
242254
.then(({ stdout, stderr }) => {
243255
if (stdout && !stderr) {
@@ -307,6 +319,7 @@ const getGitStatus = async (repoPath) => {
307319
(await execPromised(`git ls-files`, {
308320
cwd: repoPath,
309321
windowsHide: true,
322+
maxBuffer: 1024 * 10240,
310323
}).then((res) => {
311324
const { stdout, stderr } = res;
312325
if (stdout && !stderr) {

0 commit comments

Comments
 (0)