MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cgi_initialize_post

Function cgi_initialize_post

cgi-bin/var.c:1054–1126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1052 */
1053
1054static int /* O - 1 if form data was read */
1055cgi_initialize_post(void)
1056{
1057 char *content_length, /* Length of input data (string) */
1058 *data; /* Pointer to form data string */
1059 size_t length, /* Length of input data */
1060 tbytes; /* Total number of bytes read */
1061 ssize_t nbytes; /* Number of bytes read this read() */
1062 int status; /* Return status */
1063
1064
1065 /*
1066 * Check to see if there is anything for us to read...
1067 */
1068
1069 content_length = getenv("CONTENT_LENGTH");
1070 if (content_length == NULL || atoi(content_length) <= 0)
1071 return (0);
1072
1073 /*
1074 * Get the length of the input stream and allocate a buffer for it...
1075 */
1076
1077 length = (size_t)strtol(content_length, NULL, 10);
1078 data = malloc(length + 1); // lgtm [cpp/uncontrolled-allocation-size]
1079
1080 if (data == NULL)
1081 return (0);
1082
1083 /*
1084 * Read the data into the buffer...
1085 */
1086
1087 for (tbytes = 0; tbytes < length; tbytes += (size_t)nbytes)
1088 if ((nbytes = read(0, data + tbytes, (size_t)(length - tbytes))) < 0)
1089 {
1090 if (errno != EAGAIN)
1091 {
1092 free(data);
1093 return (0);
1094 }
1095 else
1096 nbytes = 0;
1097 }
1098 else if (nbytes == 0)
1099 {
1100 /*
1101 * CUPS STR #3176: OpenBSD: Early end-of-file on POST data causes 100% CPU
1102 *
1103 * This should never happen, but does on OpenBSD. If we see early end-of-
1104 * file, treat this as an error and process no data.
1105 */
1106
1107 free(data);
1108 return (0);
1109 }
1110
1111 data[length] = '\0';

Callers 1

cgiInitializeFunction · 0.85

Calls 1

cgi_initialize_stringFunction · 0.85

Tested by

no test coverage detected