Skip to content

Commit 8d3a80d

Browse files
committed
sss: sss-encrypt must read pipe data until EOF is reached
With current implementation sss-encrypt opens a pipe to the child pin, then tries to read this pipe *only once*. This might return only partial data or not data at all in case if the child pin response is slow. Fix it by reading the pipe until it is closed, and only then process the data. Also increase the response buffer from 1024 bytes to 4096 bytes to accound for larger subpin responses that can be larger than 1024 bytes. Fixes latchset#389
1 parent 9196653 commit 8d3a80d

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/pins/sss/clevis-encrypt-sss.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,34 @@ encrypt_frag(json_t *sss, const char *pin, const json_t *cfg, int assume_yes)
115115
if (!pipe)
116116
return NULL;
117117

118+
char buf[4096] = {};
119+
size_t rd = 0;
120+
json_t *tmp = NULL;
118121
while (!feof(pipe)) {
119-
char buf[1024] = {};
120-
json_t *tmp = NULL;
121-
size_t rd = 0;
122+
char tmp_buf[4096] = {};
123+
size_t tmp_rd = 0;
122124

123-
rd = fread(buf, 1, sizeof(buf), pipe);
125+
tmp_rd = fread(tmp_buf, 1, sizeof(tmp_buf), pipe);
124126
if (ferror(pipe)) {
125127
fclose(pipe);
126128
return NULL;
127129
}
128-
129-
tmp = json_pack("s+%", json_string_value(jwe), buf, rd);
130-
if (!tmp) {
130+
if (rd + tmp_rd > sizeof(buf)) {
131131
fclose(pipe);
132+
fprintf(stderr, "sss: read buffer overflow\n");
132133
return NULL;
133134
}
134-
135-
json_decref(jwe);
136-
jwe = tmp;
135+
memcpy(buf + rd, tmp_buf, tmp_rd);
136+
rd += tmp_rd;
137137
}
138+
tmp = json_pack("s+%", json_string_value(jwe), buf, rd);
139+
if (!tmp) {
140+
fclose(pipe);
141+
return NULL;
142+
}
143+
144+
json_decref(jwe);
145+
jwe = tmp;
138146

139147
fclose(pipe);
140148
waitpid(pid, &status, 0);

0 commit comments

Comments
 (0)