]> git.sur5r.net Git - cc65/commitdiff
Made some string output functions reject an invalid NULL buffer pointer.
authorGreg King <gregdk@users.sf.net>
Thu, 9 Jul 2015 18:46:28 +0000 (14:46 -0400)
committerGreg King <gregdk@users.sf.net>
Thu, 9 Jul 2015 18:46:28 +0000 (14:46 -0400)
libsrc/common/vsnprintf.s

index 94ad072caf67abe4ec0fddc20b1cab534c8c3997..01bcd64064e86ca641c60286af12e7cbae6d033b 100644 (file)
@@ -86,9 +86,16 @@ L1:     dex
         sta     bufptr+0
         stx     bufptr+1
 
+; There must be a buffer if its size is non-zero.
+
+        bit     bufsize+1
+        bmi     L5
+        ora     bufptr+1
+        bze     L0              ; The pointer shouldn't be NULL
+
 ; Restore ap and call _printf
 
-        pla
+L5:     pla
         tax
         pla
         jsr     __printf
@@ -125,6 +132,11 @@ L4:     lda     ccount+0
 ; Bail out if size is too high.
 
 L9:     lda     #ERANGE
+        .byte   $2C             ;(bit $xxxx)
+
+; NULL buffer pointers usually are invalid.
+
+L0:     lda     #EINVAL
         jsr     __directerrno   ; Return -1
         jmp     incsp6          ; Drop parameters