This is an automated email from the ASF dual-hosted git repository.

nickva pushed a commit to branch use-longer-int-types-for-couchjs
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit c5511ec258888325b73f235cbdd417a44e9a9f32
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Mon Nov 16 14:10:55 2026 -0500

    Use ssize_t for couchjs line lengths
    
    `linein()` returns length as `ssize_t` so keep it as such and don't cast it 
to
    an `int`. Exit with an error for lines which are too long.
---
 src/couch_quickjs/c_src/couchjs.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/couch_quickjs/c_src/couchjs.c 
b/src/couch_quickjs/c_src/couchjs.c
index 420f5f41d..72823d495 100644
--- a/src/couch_quickjs/c_src/couchjs.c
+++ b/src/couch_quickjs/c_src/couchjs.c
@@ -10,6 +10,7 @@
 // License for the specific language governing permissions and limitations 
under
 // the License.
 
+#include <limits.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -294,8 +295,11 @@ static JSValue js_readline(JSContext* cx, JSValueConst 
this_val, int argc, JSVal
     if(!line) {
       BAIL("Could not allocate line buffer for list sub-command");
     }
-    int len;
+    ssize_t len;
     if ((len = linein(&line, &linemax)) != -1) {
+      if (len > INT_MAX) {
+        BAIL("list linein() line too long");
+      }
       if (line[len - 1] != '\n') {
         BAIL("list linein() didn't end in newline");
       }
@@ -473,9 +477,12 @@ int main(int argc, const char* argv[])
       BAIL("Could not allocate line buffer");
     }
 
-    int len;
+    ssize_t len;
     bool do_continue = true;
     while (do_continue && (len = linein(&line, &linemax)) != -1) {
+      if (len > INT_MAX) {
+        BAIL("linein() line too long");
+      }
       if (line[len - 1] != '\n') {
         BAIL("linein() didn't end in newline");
       }

Reply via email to