| 1917 | } |
| 1918 | |
| 1919 | static int parse_data(struct strbuf *sb, uintmax_t limit, uintmax_t *len_res) |
| 1920 | { |
| 1921 | const char *data; |
| 1922 | strbuf_reset(sb); |
| 1923 | |
| 1924 | if (!skip_prefix(command_buf.buf, "data ", &data)) |
| 1925 | die(_("expected 'data n' command, found: %s"), command_buf.buf); |
| 1926 | |
| 1927 | if (skip_prefix(data, "<<", &data)) { |
| 1928 | char *term = xstrdup(data); |
| 1929 | size_t term_len = command_buf.len - (data - command_buf.buf); |
| 1930 | |
| 1931 | for (;;) { |
| 1932 | if (strbuf_getline_lf(&command_buf, stdin) == EOF) |
| 1933 | die(_("EOF in data (terminator '%s' not found)"), term); |
| 1934 | if (term_len == command_buf.len |
| 1935 | && !strcmp(term, command_buf.buf)) |
| 1936 | break; |
| 1937 | strbuf_addbuf(sb, &command_buf); |
| 1938 | strbuf_addch(sb, '\n'); |
| 1939 | } |
| 1940 | free(term); |
| 1941 | } |
| 1942 | else { |
| 1943 | uintmax_t len = strtoumax(data, NULL, 10); |
| 1944 | size_t n = 0, length = (size_t)len; |
| 1945 | |
| 1946 | if (limit && limit < len) { |
| 1947 | *len_res = len; |
| 1948 | return 0; |
| 1949 | } |
| 1950 | if (length < len) |
| 1951 | die(_("data is too large to use in this context")); |
| 1952 | |
| 1953 | while (n < length) { |
| 1954 | size_t s = strbuf_fread(sb, length - n, stdin); |
| 1955 | if (!s && feof(stdin)) |
| 1956 | die(_("EOF in data (%lu bytes remaining)"), |
| 1957 | (unsigned long)(length - n)); |
| 1958 | n += s; |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | skip_optional_lf(); |
| 1963 | return 1; |
| 1964 | } |
| 1965 | |
| 1966 | static int validate_raw_date(const char *src, struct strbuf *result, int strict) |
| 1967 | { |
no test coverage detected